I\'m using xUnit.net, AutoFixture and SemanticComparison and want to verify the results of a mapping.
On the individual item level, I\'m well covered.
Given<
Given some AssertResemblance.Like Collection helpers[1], you
SemanticComparison grows a feature I don't think it can be usefully generalised)Ploeh.SemanticComparison's Likeness do the matching on NameFinal result is:
var results = from result in outputs orderby result.Name select result;
var expectations = from input in inputs orderby input.Name select input;
AssertResemblance.Like( expectations, results,
configure=>configure
.Without(x=>x.IgnoreThisField) );
[1]
static class AssertResemblance
{
public static void Like( IEnumerable expected, IEnumerable actual )
{
Like( expected, actual, x=>x );
}
public static void Like( IEnumerable expected, IEnumerable actual, Func, Likeness> configureLikeness )
{
Assert2.Collection( actual, SelectShouldEqualAsAction( expected.Select( x => configureLikeness( x.AsSource().OfLikeness() ) ) ) );
}
public static void Like( IEnumerable expected, IEnumerable actual, Func, IEnumerable> unify )
{
Like( expected, actual, unify, x=>x );
}
public static void Like( IEnumerable expected, IEnumerable actual, Func,IEnumerable> unify, Func, Likeness> configureLikeness )
{
Assert2.Collection( unify( actual ), SelectShouldEqualAsAction( unify(expected).Select( x => configureLikeness( x.AsSource().OfLikeness() ) ) ) );
}
static Action[] SelectShouldEqualAsAction( IEnumerable> that )
{
return (from it in that select (Action)it.ShouldEqual).ToArray();
}
}