Replies: 3 comments
-
it is because struct are value types, and as such they are using the ComparingByValue strategy. (using the Equals, the inherited one in your case) it is by design it's explained here: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1815
which is equivalent of calling Object.ReferenceEquals, so since your instances of the struct (without an Equals method) do not share the same reference, then it says that they are not equivalent. by using AssertionOptions.AssertEquivalencyUsing(options => options it will force a referenceType comparison strategy. Also related to
your guts were onto something from MSDN
in your case the SubscriptionsFees is a byte-by-byte comparaison because all fields are value types, and the tricky part in your case is that SubscriptionCommitmentTerm is using a reference type, but going fast over the code we can miss it
an array is a reference type. |
Beta Was this translation helpful? Give feedback.
-
@dennisdoomen is there a policy/config/setting to set ComparingByMembers for everything? if there isnt, i might be down to do it |
Beta Was this translation helpful? Give feedback.
-
There's an |
Beta Was this translation helpful? Give feedback.
-
Description
Using latest version 6.12.0
When trying to use BeEquivalentTo to compare 2 objects with a few properties, the assertion is failing even if the objects are identical.
Reproduction Steps
Expected behavior
The BeEquivalentTo should give true because they are exactly the same. I thought it could be related to the struct but the SubscriptionFees are also a struct and they compare correctly. The error started happening when I added the CommittedMinimalQuantity DTO. If I remove that property from the DTO, the rest compares correctly, but I can't seem to pinpoint what specifically makes the comparison fail in that one.
Actual behavior
The assertion fails with this error.
Kdiff on the given error is identical.
Oddly, trying to using exclusion options on all properties of the DTO still makes it not equivalent.
Regression?
No response
Known Workarounds
In the meantime, making my assertion like this works for my test case. I exclude the problematic DTO, and I compare each property separately. Notice how the CommittedMinimalQuantities compares correctly, even though its introduction breaks the BeEquivalentTo.
Configuration
No response
Other information
No response
Are you willing to help with a pull-request?
No
Beta Was this translation helpful? Give feedback.
All reactions