MSTest: How to assert 2 collections
I am trying to make a unit test to see if the objects in 1 collection (and the order for that matter) are the same (as in different objects, same values) as the ones in another collection.
This fails, as apparently CollectionAssert.AreEqual is a reference test.
2 Replies
Tests whether the specified collections are equal and throws an exception if the two collections are not equal. Equality is defined as having the same elements in the same order and quantity. Whether two elements are the same is checked using Equals(Object, Object) method. Different references to the same value are considered equal.sounds like ur
Trophy
type doesnt do the equality check correctly.
so either fix GetHashCode()
, Equals(object)
(and probably also implement IEquatable<Trophy>
),
or use CollectionAssert.AreEqual()
overload that takes an IComparer
and pass a one in that does the equality check as u want it to bemuch obliged