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.
Example:
var myList = Enumerable.Range(1, 5);
var expected = new[]
{
1, 2, 3, 4, 5
};
//succeeds
myList.ShouldBeEquivalentTo(expected, options => options.WithStrictOrdering());
//fails
myList.Reverse().ShouldBeEquivalentTo(expected, options => options.WithStrictOrdering());
Read more about these options in the documentation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…