Why does this test method fail?
You can also use CollectionAssert
instead of Assert
:
CollectionAssert.AreEqual(expected, actual);
I think it is much more simple and fancier than a loop over the collection of your test cases.
Does AreEqual only check equality of the reference, not the contents?
Yeap.
To test the contents you could:
Assert.AreEqual(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.AreEqual(expected[i], actual[i]);
}
The Assert.AreEqual()
method does a reference equality test as you expected.
Assuming you're using .Net 3.5 or above, you can do this:
using System.Linq;
Assert.IsTrue(expected.SequenceEqual(actual));
Edit: Clarified when this option is available.
I think that this is what your are looking for:
Assert.IsTrue(expected.SequenceEqual(actual));
Check this question