I have a two Lists which contains two User objects inside.
Objects inside lists are same for their values.
But when i am checking this lists Unit test return CollectionAssert.AreEqual
failed. (Element at index 0 do not match).
I think CollectionAssert.AreEqual
method does not checking list for their values, it checking for the reference.
My question is how can i compare two list in Unit test for their value?
public class User
{
public string Name { get; set; }
public string Password { get; set; }
}
[TestMethod]
public void CheckUserList()
{
List<User> users = new List<User>()
{
new User(){ Name="Name", Password="Pass" },
new User(){ Name="Name1", Password="Pass1" },
new User(){ Name="Name2", Password="Pass2" },
};
List<User> users1 = new List<User>()
{
new User(){ Name="Name", Password="Pass" },
new User(){ Name="Name1", Password="Pass1" },
new User(){ Name="Name2", Password="Pass2" },
};
CollectionAssert.AreEqual(users, users1);
}