21 March, 2015

UnitTesting – not all arrays are created equal

Attempting to compare 2 arrays today that indeed was supposed to be containing the exact same values using the Microsoft built-in Unit testing framework (Microsoft.VisualStudio.TestTools.UnitTesting), I was greatly surprised to learn that neither Assert.Equal nor Assert.AreSame does work for arrays?

It turns out that an entirely different Assert object is to be used for that purpose!
The CollectionAssert.AreEqual(expected, actual) is what you want to use for array comparison as seen below.

    //clone object
var newDisp = disp.CloneWithoutContentData();
Assert.IsNotNull(newDisp);
Assert.IsNotNull(newDisp.Content);

CollectionAssert.AreEqual(new byte[0], newDisp.Content.Data);
CollectionAssert.AreEqual(new byte[0], newDisp.AttachmentList[0].Content.Data);

Well – you learn every day (luckily!)


Technorati Tags: ,

No comments:

InRiver: Not loading your extensions?

(You really need to in the loop to appreciate the issue this post addresses). Man, I've been fighting this problem for hours before I ...