mardi 22 septembre 2015

Comparison of two collections with Fluent Assertions

I want to check if two collections are the same. I want to compare the elements by value. The problem is that I have a class with a lot of other classes as properties. Short, I have a lot of data, which is all shown in the output when the test fails.

List<Class A>
{
    new Class A
    {
        Property1 = xyz,
        Property2 = xyz,
        ...
        Property3 = new List<Class B>()
    }
}

Hereby Class B looks like

Class B
{
   Property1,
   Property2, //let it be Class C with several properties
   ...
}

First attempt was to compare the two lists like this:

actual.Should().Equal(expected, CustomCompare);

This way all the properties are displayed in the output window but I want to ignore Property 2 in Class B for example. (That's where most of the data comes from)

Second attempt was to use ShouldBeEquivalentTo() and use the parameter Exclude(path to Property 2 in Class B)

This way I didn't get an overview of the collection contents though and I need that for comparison.

Aucun commentaire:

Enregistrer un commentaire