I have a unit test for a method which gets an object from a collection. This keeps failing and I cannot see why, so I have created a very simple test below to create 2 suppl
The default implementation of Object.Equals
for reference types (ie. classes) is "Reference Equality": are the two objects actually the same instance. It doesn't compare the values of fields.
Either (as others have shown) override Equals
to give "Value Equality". In this caseyou must also override GetHashCode
(so containers work), and should override operator ==
.
Alternatively accept that most entities should have reference equality (two suppliers with the same name are not always the same organisation) and actually use the properties directly.