Skip to content

Allow using an IEqualityComparer in BeEquivalentTo #1236

@dennisdoomen

Description

@dennisdoomen

Actually, 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()));

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions