i have a problem with a c# test method.
it looks like:
public void GetRolesTest()
{
RoleProvider target = new RoleProvider();
string username = "FOO";
string[] expected = new string[2];
expected[0] = "Admin";
expected[1] = "User";
string[] actual;
actual = target.GetRoles(username);
Assert.AreEqual<string[]>(expected, actual);
}
the method which is tested just makes the following:
public override string[] GetRoles(string username)
{
string[] output = new string[2];
output[0] = "Admin";
output[1] = "User";
return output;
}
after running the test i get the following error:
Error in "Assert.AreEqual". Expected:<System.String[]>. Acutally:<System.String[]>.
can sombody tell me what is wrong there?
The reason you got your exception is that
Assert.AreEqualwill use default comparer for type which in case ofstring[]would be simple reference comparison (actualandexpectedare different objects – different references).You can use collection assertion instead:
Or, doing
trueverification with LINQ: