How does the Assert.AreEqual(object, object)
method (in the namespace Microsoft.VisualStudio.TestTools.UnitTesting
) determine whether the paramet开发者_如何学JAVAers are equal? Does it make use of the Object.Equals(object, object)
method (in the System
namespace)?
using reflector you can see that it does indeed use Object.Equals.
public static void AreEqual<T>(T expected, T actual, string message, params object[] parameters)
{
if (!object.Equals(expected, actual))
{
string str;
if (((actual != null) && (expected != null)) && !actual.GetType().Equals(expected.GetType()))
{
str = (string) FrameworkMessages.AreEqualDifferentTypesFailMsg((message == null) ? string.Empty : ReplaceNulls(message), ReplaceNulls(expected), expected.GetType().FullName, ReplaceNulls(actual), actual.GetType().FullName);
}
else
{
str = (string) FrameworkMessages.AreEqualFailMsg((message == null) ? string.Empty : ReplaceNulls(message), ReplaceNulls(expected), ReplaceNulls(actual));
}
HandleFail("Assert.AreEqual", str, parameters);
}
}
精彩评论