error with two string[] and AreEqual in a C# Test

c#, mstest, unit-testing

Solution

The reason you got your exception is that `Assert.AreEqual` will use default comparer for type which in case of `string[]` would be simple reference comparison (`actual` and `expected` are different objects - different references).

You can use collection assertion instead:

CollectionAssert.AreEquivalent(expected, actual);

Or, doing `true` verification with LINQ:

Assert.IsTrue(actual.SequenceEqual(expected));

Problem

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?

Original source