New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IsEquivalentTo and BeEquivalentTo do not handle member hiding #956
Comments
Nice catch. |
Pfew, this proofs to be much more complex to fix than I thought. Just saying... |
I suspect this fix caused a breaking change for us with the move from 5.4.2 to 5.5: We globally configure the
We have one test which stopped working, again in connection with
Now fails with:
Notice the comparison of the Mock.MutableInvocations property. IMHO comparison of this property could never have resulted in equal. With 5.4.2 the test passes (no code changes). I deduct 5.4.2 hasn't compared this property. FixThis one is easy enough to fix by adjusting the
Release NotesIt might be worth mentioning this in the release notes? |
Thanks for that note @BrunoJuchli. Essentially < 5.5 contained a false positive that was fixed. I'll update the release notes. |
Description
I noticed the implementation for IsEquivarentTo in TypeExtensions considers two members to be equivalent if they have the same name and the declaring type of either property is the same or inherits the type of the other property. This is incorrect due to member hiding.
Complete minimal example reproducing the issue
E.g.
Expected behavior:
Main
should execute successfully, because the two properties are different and the two instances ofB
are equivalent when comparing only the null arrays.Actual behavior:
Both assertions throw because of the logic error in
IsEquivalentTo
. The second assertion throws because the logic forBeEquivalentTo
gets the property from the expression and then usesIsEquivalentTo
to compare it against other properties later.Versions
Additional Information
Using
Excluding(b => ((A)b).Property)
instead ofIncluding(b => b.Property)
does not work either because the code for extracting the member from the expression does not support casts.The text was updated successfully, but these errors were encountered: