Allow using an IEqualityComparer in BeEquivalentTo
See original GitHub issueActually, regarding my suggestion, it would also work if you could supply an EqualityComparer for EquivalencyAssertionOptions, or is it already possible? I’m just saying because EqualityComparer is the “standard” .NET way of doing it, and often there is already a suitable equality comparer available that could be reused as is. At least in our case, I like writing EqualityComparers because they nicely encapsulate the equivalency. I don’t like repeating equivalency rules in-line, because usually the same rules are needed in many places. I guess you could encapsulate them as IEquivalencySteps, but why do that if you already have EqualityComparer?
For example
orderDto.Should().BeEquivalentTo(order, options => options
.Using<DateTimeEqualityComparer>());
or
orderDto.Should().BeEquivalentTo(order, options => options
.Using<DateTime>(new DateTimeEqualityComparer()));
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to use a specific comparer func for Equality in ...
1 Answer 1 ... Why don't you replace the call to BeEquivalentTo with a custom assertion built on top of Execute.Assertion as documented...
Read more >Object graph comparison
BeEquivalentTo () compares Enum members by the enum's underlying numeric value. An option to compare an Enum only by name is also available,...
Read more >Fluent Assertions 6.0, the biggest release ever
And for the more complicated cases, you can use NotContainEquivalentOf to assert the absence of an element in the collection using the same ......
Read more >Releases - Fluent Assertions
NotContainMatch() to assert that the collection does not contain a string that matches a wildcard pattern - #1246. The Using / When option...
Read more >IEqualityComparer<T> Interface
This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality for type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I really like this idea! Agree with @jnyrup that the second is more generic and clearer. I’ve been struggling with comparing types in a homegrown library to C# types. Using the DifferentObjectsEquivalencyStep approach I found on SO has been successful up to a point.
I like the second one the most. It’s explicit and generic.
or
I’m not sure what the signature of the first one would be?
I dislike that as:
IEqualityComparer<T>
and not the non-genericIEqualityComparer
comparer
.In general I’d like to take Fluent Assertions to a more generic world.