In C# ,Compare two collections in unit test
In C# if we want to compare two collections and if elements in the two collections are not in the same order then use CollectionAssert.AreEquivalent method Let's discuss in the example , as shown in the below code , expectedCollection items have Honda,Toyota,Ford and in the actualCollection items are in the different order and have Toyota,Honda,Ford then to compare two collection use CollectionAssert.AreEquivalent method. List expectedCollection = new List { "Honda", "Toyota", "Ford" }; List actualCollection = new List { "Toyota", "Honda", "Ford" }; CollectionAssert.AreEquivalent(Test1, Test2, "Collection Assert failed"); The difference between CollectionAssert.AreEqual and CollectionAssert.AreEquivalent is that in CollectionAssert.AreEqual method it will verify the collection items in the same order but in the CollectionAssert.AreEquivalent method can verify the collection items in any ...