Excellent - polishing and packaging

I use Ploeh.SemanticComparison Likenessas a way to effectively express the intended outputs of the matching process (as described in the Mark Seemann excellent Advanced Unit Testing course on PluralSight ).

I am testing that some data is being displayed correctly, which is as follows:

[Theory, AutoData]
static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id )
{
    var result = sut.SyncProduct( name, version, id );

    var expected = new { ProductId = id, Name = name, Version = version };
    expected.AsSource().OfLikeness<NewMappingsEvent>()
        .Without( y => y.ProgrammaticIdentifier)
        .ShouldEqual(result);
}

However, I am not satisfied: -

  • I want to apply the name to the affinity (i.e. the name of my setting .Without( y => y.ProgrammaticIdentifier))
  • I lost symmetry with Assert.Equal( expected,actual, comparer)(but I definitely need an error message from ShouldEqual)

Is there a cleaner way to express this within expressed limits?

+1
source share
1

Assertion AssertResemblance (, [4]) static, [1], :

var expected = new { ProductId = id, Name = name, Version = version };
AssertResemblance.Like( expected, result, WithoutProgrammaticIdentifier );

, , [2], :

AssertResemblance.Like( expected,result,x=>x.WithoutProgrammaticIdentifier());

( , ), ( ) ([ 2]), [3].


[1]

public static Likeness<T, NewMappingsEvent> WithoutProgrammaticIdentifier<T>( Likeness<T, NewMappingsEvent> that )
{
    return that.Without( x => x.ProgrammaticIdentifier );
}

[2]

static class NewMappingsEventResemblances
{
    public static Likeness<T, NewMappingsEvent> WithoutProgrammaticIdentifier<T>( this Likeness<T, NewMappingsEvent> that )
    {
        return that.Without( x => x.ProgrammaticIdentifier );
    }
}

[3]

static Likeness<T, NewMappingsEvent> WithoutProgrammaticIdentifier<T>( Likeness<T, NewMappingsEvent> that )
{
    return that.WithoutProgrammaticIdentifier();
}

[4]

static class AssertResemblance
{
    public static void Like<T, T2>( T expected, T2 actual )
    {
        Like( expected, actual, x => x );
    }

    public static void Like<T, T2>( T expected, T2 actual, Func<Likeness<T, T2>, Likeness<T, T2>> configureLikeness )
    {
        var likeness = expected.AsSource().OfLikeness<T2>();
        configureLikeness( likeness ).ShouldEqual( actual );
    }
}
+1

All Articles