14

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).

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
ripper234
  • 222,824
  • 274
  • 634
  • 905

1 Answers1

28

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.

Mark Dickinson
  • 6,573
  • 4
  • 29
  • 41