Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSTest Assert.AreEqual fails with string array

I'm working up some unit tests and unsure why this particular test is failing.

The test is to assert that a custom view engine looks in the correct place for views.

In my custom view engine is this:

AreaMasterLocationFormats = new[]
{
    "~/Areas/{2}/App/{1}/Views/{0}.cshtml",
    "~/Areas/{2}/App/Shared/Views/{0}.cshtml"
};

And in my test is this:

string[] expected = new[]
{
    "~/Areas/{2}/App/{1}/Views/{0}.cshtml",
    "~/Areas/{2}/App/Shared/Views/{0}.cshtml"
};

CustomRazorViewEngine engine = new CustomRazorViewEngine();

Assert.AreEqual(expected, engine.AreaMasterLocationFormats);

The test fails with the message:

Message: Assert.AreEqual failed. Expected:<System.String[]>. Actual:<System.String[]>.

(s/o's quote format doesn't like the second lt in that...)

I'm unsure why, as when I debug the test all appears well.

like image 635
jleach Avatar asked Oct 22 '25 14:10

jleach


1 Answers

You need to use CollectionAssert instead:

CollectionAssert.AreEqual(expected, engine.AreaMasterLocationFormats);

See MSDN

like image 191
haim770 Avatar answered Oct 25 '25 07:10

haim770



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!