Unit testing and objects equality
February 16th, 2009Let's assume that we have a class like below:
C#:
-
public class Foo : IEquatable<Foo>
-
{
-
private int variable;
-
-
public int Variable
-
{
-
get { return variable; }
-
set { variable = value; }
-
}
-
-
#region IEquatable<Foo> Members
-
-
public bool Equals(Foo other)
-
{
-
return this.variable == other.Variable;
-
}
-
-
#endregion
-
}
and a unit test for that:
C#:
-
[TestClass()]
-
public class FooTest
-
{
-
[TestMethod()]
-
public void EqualsTest()
-
{
-
one.Variable = 5;
-
two.Variable = 5;
-
-
Assert.AreEqual<Foo>(one, two, "AreEqual<Foo> failed");
-
Assert.AreEqual(one, two, "AreEqual failed");
-
Assert.AreSame(one, two, "AreSame failed");
-
}
-
}
and a question is - which Assert fails? All of them o_O
I could not find an explanation why implemented Equals method is not called. Framework always calls default Equals(object)
