Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare lists using fluent-assertions?

I want to compare a list of objects, ignoring the order of the objects in the list and only comparing some of the properties in the objects, currently I'm using the following code to perform this comparison:

actual.Should().NotBeNull();
actual.Count.Should().Be(expected.Count);
//compare ignoring order
foreach (var exp in expected)
    actual.Should().Contain(act =>
        act.IndividualId.Equals(exp.IndividualId)
        && act.Email.Equals(exp.Email)
        && act.FirstName.Equals(exp.FirstName)
        && act.LastName.Equals(exp.LastName)
    );

However this seems less than ideal, as when there is a failure you do not get a print out of the expected values. Is there a built in mechanism for performing this comparison using fluent assertions?

like image 706
setebos Avatar asked Mar 20 '13 00:03

setebos


1 Answers

Not right now. We do have the new equivalency assertion syntax of FA 2.0, but that will also verify if the objects appear in the right order. For FA 2.1 I'm trying to support that, but I'm not sure yet if that will work. It basically means it has to compare the entire object graph behind a collection item with the object graphs for each and every other item in the collection. Surely it will be rather slow.

like image 139
Dennis Doomen Avatar answered Oct 05 '22 03:10

Dennis Doomen