I\'m new to unit testing and NUit in particular. I\'m just typing some examples from the book which refers to Java and JUnit. But I\'m using C# instead.
The problem
I found it confusing that implementing the IEquatable interface, which also has an
Equals(T other)
method, posed me with the same problem as described above.
The only reason I chose to use the IEquaytable interface above overriding the Equals method was not to have to do the type check.
In the end I had to use the following code
public bool Equals(CustomTag other)
{
return (other.Name.Trim().ToLower() == Name.Trim().ToLower());
}
public override bool Equals(object o)
{
if (o is CustomTag)
{
return Equals(o as CustomTag);
}
return false;
}
but then I thought, why not just leave the IEquatable interface for what it is and only override the Equals method. (less code = better)