You are definitely correct.
I was wrestling with a similar problem earlier today, until I found your post and am now sure, that NUnit IsEqualTo() does not consistently call the Equals overrides provided.
I say consistently, because sometimes it does. As a matter of fact I have two classes. The second one derived from the first. When I call Is.EqualTo() on instances of the first, NUnit calls the Equals overrides, for instances of the second it does not.
While that is very peculiar, I have no time to investigate further into what is going on.
People with similar problems or solutions should definitely post about it, as this is a very annoying thing and actually had me doubt the validity of my tests.
In the meantime I created the following Affirm class, which calls the Equals overrides for sure (I checked it). It uses NUnit to do a simple equality Assert instead of Is.EqualTo() and somewhat remedies the fact, that this way NUnit doesn't give string representations of the objects in case the test fails.
So here it is:
using NUnit.Framework;
public static class Affirm
{
public static Affirmer That(object actual)
{
return new Affirmer(actual);
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public class Affirmer
{
readonly object _actual;
public Affirmer(object actual)
{
_actual = actual;
}
public void IsEqualTo(object expected)
{
string failureMessage = string.Format("\nExpected: <{0}>\nBut was: <{1}>", _actual, expected);
Assert.That(_actual.Equals(expected), Is.True, failureMessage);
}
public void IsNotEqualTo(object expected)
{
string failureMessage = string.Format("\nDid not excpect: <{0}>\nBut was: <{1}>", _actual, expected);
Assert.That(_actual.Equals(expected), Is.False, failureMessage);
}
}
Use it like this:
Affirm.That(actualObject).IsEqualTo(expectedObject);
and
Affirm.That(actualObject).IsNotEqualTo(expectedObject);
Hope this helps.