FluentAssertions: equivalence of sorted lists

By default, ShouldBeEquivalentTo() will ignore the order in the collections because in most cases two collections are equivalent if they contain the same items in any order. If you do care about the order, just use one of the overloads of WithStrictOrdering() on the options => parameter.


var myList = Enumerable.Range(1, 5);
var expected = new[]
    1, 2, 3, 4, 5

myList.ShouldBeEquivalentTo(expected, options => options.WithStrictOrdering());

myList.Reverse().ShouldBeEquivalentTo(expected, options => options.WithStrictOrdering());

Read more about these options in the documentation.

Leave a Comment