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
If you want to compare two different instances of Supplier, and want them to be considered equal when certain properties have the same value, you have to override the Equals method on Supplier and compare those properties in the method.
You can read more about the Equals method here: http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx
Example implementation:
public override bool Equals(object obj)
{
if (obj is Supplier)
{
Supplier other = (Supplier) obj;
return Equals(other.SupplierID, this.SupplierID) && Equals(other.SupplierName, this.SupplierName);
}
return false;
}
Note that you'll also get a compiler warning that you have to implement GetHashCode as well, that could be as simple as this:
public override int GetHashCode()
{
return SupplierID;
}