-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
I came across this question on Stack Overflow where someone uses Optional in combination with FA.
Optional provides a generic struct Option<T> that overrides Equals, so FA assumes value semantics.
Now if one would want to override this behavior globally, so Option<T> uses ComparingByMembers for any T, one had to add a call to AssertionOptions.AssertEquivalencyUsing for each T.
A (simplistic) workaround for this is an extension method like this:
public static class FluentAssertionsExtensions
{
public static void BeEquivalentByMembers<TExpectation>(
this ComparableTypeAssertions<TExpectation> actual,
TExpectation expectation)
{
actual.BeEquivalentTo(
expectation,
options => options.ComparingByMembers<TExpectation>());
}
}If an override that supports a Type argument existed, the following would be possible:
AssertionOptions.AssertEquivalencyUsing(options => options.ComparingByMembers(typeof(Option<>))