c# - Comparing Two objects using Assert.AreEqual() -


I'm writing test cases for the first time in Visual Studio # I is a method that gives a list of objects And I want to compare it with the second list of items using the assert.AreEqual () method.

I tried to do this, but the claim fails even if both objects are the same. / P>

I want to know that this method is comparing the contents of two parameter references or the object,

Do I have to overload the operator == To work this?

If you are using NUnit then this is the same documentation That

starting with version 2.2, special provision has also been made to compare single dimensional arrays. Two arrays will be considered equivalent to the dependent. If they are the same length and the related elements are equal to each. Note: Multi-directional arrays, arrays arrays, and other collection types such as ArrayList are not currently supported.

In general, if you are comparing two objects and you want the values ​​based parallelism you must override the similarity method.

To achieve what you are looking for:

  class person {public string firstname {get; Set;} public string last name {get; Set;} Public override baul par (object other) {var toCompareWith = as another person; If (toCompare == empty) return false; Return it. First name == Comprehensive with: first name & amp; Amp; This.Lastname == toCompareWith.Lastname; }}   

And in your unit test:

  Fear. Reequal (Expected list. ToArray (), Actual list. ToArray ());    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -