-
-
Notifications
You must be signed in to change notification settings - Fork 541
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
ComparingByMembers<object> lets structural equality assertions always succeed #1374
Comments
After some debugging through FluentAssertions, I found out that the above test fails when the string values for I think the problem is that when Adding a This leads me to the conclusion that I would need something like: compare all reference types by members. |
Is there a way to detect that a type is F#-specific? |
Yes. From F# code you can use e.g. |
Another solution for my problem would also be when I could register a callback with the following signature:
Then I could do the checking for F# types on my own. |
That's what I was thinking,e.g. |
I think that would work. Should I try to contribute that? |
We probably should change the Signature to:
So I can pass I was able to build a prototype and will check some cases with it. |
It could be just an overload of |
You can find my prototype at https://github.com/ursenzler/fluentassertions/tree/comparingByMembersCallback. My use case works correctly this way. I'm not sure how you'd like the tests to look like. I didn't find a way to align them with the existing tests because the new method is an additional way to accomplish what is already there. |
Thanks for taking a stab at it. The problem with your implementation is that multiple calls to your overload will only remember the last predicate, which is different from the other methods. That's why I was suggesting to have a collection of predicates. |
Ah, now I understand: Collecting a collection of I'll change that... |
Okay, after misunderstanding everything :-D, here a new - hopefully better - version: https://github.com/ursenzler/fluentassertions/blob/f3598478a92f20172a5d8fcb69d0a65aa93ad1a2/Src/FluentAssertions/Equivalency/SelfReferenceEquivalencyAssertionOptions.cs#L165 This time with some Facts, as well. |
Yep, this looks much closer to what I had in mind. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sorry for being late at the party. The bug here seems to stem from EqualityStrategy IEquivalencyAssertionOptions.GetEqualityStrategy(Type type)
{
EqualityStrategy strategy;
if (referenceTypes.Any(type.IsSameOrInherits))
{
strategy = EqualityStrategy.ForceMembers;
} where A solution that seems to work is to change the conditional to if (!type.IsPrimitive && referenceTypes.Any(type.IsSameOrInherits)) With that change the
|
That could be a simpler solution than #1383 I'll check it against our codebase. |
@ursenzler When you get around testing against your codebase the fix has been merged to |
@jnyrup First, thanks for the info! |
But in general, I think it works - I got some simpler scenarios, which don't need equivalency steps, to work. |
@ursenzler Glad to hear it worked out. Regarding
I'm open to keep it public in v6. Note that the class is currently undergoing some changes in https://github.com/fluentassertions/fluentassertions/pull/1379/files#diff-5aca5b14c46d3fb96ba470da10e4efe4 |
Since it's extending our own code, I think I need to move it either to the |
Description
I want to be able to configure FluentAssertions' structural equality so that it uses ComparingByMembers for all types.
The background for this is that I have a mix of F# and C# code and all F# records implement Equals by default. In case of an object-graph with a mix starts using
Equals
when hitting the first F# record, as well for the nested C# classes.I tried
ComparingByMembers<object>
, but that results in the tests always being succeeded. And I guess that should be fixed.Complete minimal example reproducing the issue
Expected behavior:
All types are structurally compared correctly.
Actual behavior:
Assertion always succeeds.
Versions
Additional Information
None.
The text was updated successfully, but these errors were encountered: