tags:

views:

35

answers:

2

The following method fails:

[TestMethod]
public void VerifyArrays()
{
    int[] actualArray = { 1, 3, 7 };
    Assert.AreEqual(new int[] { 1, 3, 7 }, actualArray);
}

How do I make it pass without iterating over the collection?

+8  A: 

Microsoft has provided a helper class CollectionAssert.

[TestMethod]
public void VerifyArrays()
{
    int[] actualArray = { 1, 3, 7 };
    CollectionAssert.AreEqual(new int[] { 1, 3, 7 }, actualArray);
}
Kevin Driedger
+1  A: 

You can use the Enumerable.SequenceEqual() method.

[TestMethod]
public void VerifyArrays()
{
    int[] actualArray = { 1, 3, 7 };
    int[] expectedArray = { 1, 3, 7 };

    Assert.IsTrue(actualArray.SequenceEqual(expectedArray));
}
Daniel Brückner