FluentAssertions 如何比较 2 个对象(使用反射或其他方式)?

Ngu*_*ong 1 c# asp.net-mvc nunit unit-testing fluent-assertions

我目前正在使用FluentAssertion比较 2 个对象。

\n\n

我很想知道它是用什么方式来比较的?

\n\n

使用Reflection像这样

\n\n
public static void PropertyValuesAreEquals(object actual, object expected)   \n{\n        PropertyInfo[] properties = expected.GetType().GetProperties();\n        foreach (PropertyInfo property in properties)\n        {\n            object expectedValue = property.GetValue(expected, null);\n            object actualValue = property.GetValue(actual, null);\n          if (!Equals(expectedValue, actualValue))\n                Assert.Fail("Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name, expectedValue, actualValue);\n    //\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6.\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果用另一种方式来比较,那是什么呢?

\n

Den*_*men 5

我建议您阅读文档以了解它使用的算法。但我可以告诉你,它充满了反思。