Assert.AreEqual(object, object)
方法(在命名空间Microsoft.VisualStudio.TestTools.UnitTesting
中)如何确定参数是否相等?它是否使用Object.Equals(object, object)
方法(在System
命名空间中)?
答案 0 :(得分:8)
使用reflector你可以看到它确实使用了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);
}
}