Reference type comparison.
Try using CollectionAssert.AreEqual or CollectionAssert.AreEquivalent.
https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.areequivalent.aspx
Here's what happens:
You are using Assert.AreEqual(List<int>, List<int>) , from which CLR / .NET enters and says: "is the List 1 link the same as in List 2?" As a result, no, so CLR / .NET will send you a false testimony.
CollectionAssert lists arrays (which are internal lists) and determines whether they have the same elements. CollectionAssert.AreEqual make sure they have the same elements in the same order. CollectionAssert.AreEquivalent make sure they have the same elements in any order.
ANY array / list / dictionary MUST use CollectionAssert for such comparisons.
For instance:
List<int> l1 = new List<int>(); List<int> l2 = l1; Assert.AreEqual(l1, l2);
This will lead to true because l2 set to the same link as l1 .
but
List<int> l1 = new List<int>(); List<int> l2 = new List<int>(); Assert.AreEqual(l1, l2);
This will result in false due to l2 , making NEW a reference to the NEW object. Taking into account that
CollectionAssert.AreEqual(l1, l2);
In the above situation, true will be given. This is because the CLR / .NET does go through the list and inventory it essentially.
Another edit, because I wanted to clarify: you can also use CollectionAssert.AreEquivalent , which will not guarantee the elements in the same order, but simply ensures that arrays / lists / dictionaries have the same number of identical Items. I.e:.
1,2,3,3,2,1 1,3,2,2,3,1
This will result in true with CollectionAssert.AreEquivalent , but false with CollectionAssert.AreEqual .