public class Student
{
public string Name { get; set; }
public int ID { get; set; }
}
...
var st1 = new Student
{
ID =
If you use NUnit you may using this syntax and specify an IEqualityComparer specifically for the test:
[Test]
public void CompareObjectsTest()
{
ClassType object1 = ...;
ClassType object2 = ...;
Assert.That( object1, Is.EqualTo( object2 ).Using( new MyComparer() ) );
}
private class MyComparer : IEqualityComparer
{
public bool Equals( ClassType x, ClassType y )
{
return ....
}
public int GetHashCode( ClassType obj )
{
return obj.GetHashCode();
}
}
See also here: Equal Constraint (NUnit 2.4 / 2.5)