To determine if 2 collections are equal, NUnit must ultimately compare the values ββinside the collection. In this case, the values ββare of type ExampleClass , which is equal to class . It does not implement any equality testing (for example, overrides Equals and GetHashCode), so NUnit will eventually make a comparative comparison. This will fail because each collection contains different instances of Example , although the fields have the same values.
You can fix this by adding the following to ExampleClass
public override bool Equals(object o) { var other = o as ExampleClass; if ( other == null ) { return false; } return this.Description == other.Description && this.SKU == other.SKU && this.Price == other.Price && this.Qty == other.Qty; } public override int GetHashCode() { return 1; }
Note. I chose a value of 1 for GetHashCode because it is a mutable type, and the only really safe return value for GetHashCode on a mutable type is constant. If you intend to use this as a key in Dictionary<TKey,TValue> , although you will want to return to it.
Jaredpar
source share