Search code examples
c#autofixturesemantic-comparison

Is it possible in AutoFixture SemanticComparison to set custom comparer for specified type


Is it possible in AutoFixture SemanticComparison to set custom comparer for specified property of a object or for specified type.

For example you need to compare objects that have property of type DateTime. You want to compare them using Likenes but you want the precision of the comparison to discard differences on milliseconds level (possibly you lost precision after retrieving DateTime from database).


Solution

  • You may use the EqualsWhen member of the Likeness (Fluent) API for doing that.

    Here is a quite similar example.