Assert.AreEqual(object,object)方法

时间:2011-06-25 16:56:43

标签: c# .net unit-testing mstest assert

Assert.AreEqual(object, object)方法(在命名空间Microsoft.VisualStudio.TestTools.UnitTesting中)如何确定参数是否相等?它是否使用Object.Equals(object, object)方法(在System命名空间中)?

1 个答案:

答案 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);
    }
}