Comparing Two objects using Assert.AreEqual()

These answers are far too complicated for the issue. There are no overrides necessary to compare two Lists, and you do not need to break out multiple asserts.
Microsoft uses the following class, CollectionAssert.

CollectionAssert.AreEqual(expectedList, actualList)

This works for Lists, Dictionaries, and whatever else implements ICollection interface.

The microsoft documentation is at the following location and details the various types of assertions which can be made on collections

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx

However, as mentioned by @Bart, this does not work as expected on Lists of (complex) Objects, and the Equals method may still need to be overwritten for those cases.

Leave a Comment