Reputation: 230206
I know how to check that a collection is ordered by some property:
Assert.That(actual, Is.Ordered.By("Foo"));
How can I assert that actual contains the elements (1,2,5,3,4) in this specific order (without writing a custom comparer).
Upvotes: 14
Views: 6439
Reputation: 6633
Use
CollectionAssert.AreEqual(expectedIEnumerable, actualIEnumerable);
This checks that the items are equal and are in the same order.
I'm fairly sure that when you use Assert.That on a collection, you get collection assert functionality. So you can say stuff like
Assert.That(collection, Is.EqualTo(expectedCollection)); // Same order
or
Assert.That(collection, Is.EquivalentTo(expectedCollection)); // Same item count
as well as stuff like
Assert.That(collection, Has.Count.EqualTo(expectedSize));
The Has keyword opens you up to the stuff that was specific to collection asserts, and is really useful.
Upvotes: 29