【发布时间】:2020-03-24 22:10:57
【问题描述】:
我目前正在使用FluentAssertion 来比较 2 个对象。
我真的很想知道它用什么来比较?
使用Reflection 然后像这样循环所有道具?
public static void PropertyValuesAreEquals(object actual, object expected)
{
PropertyInfo[] properties = expected.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
object expectedValue = property.GetValue(expected, null);
object actualValue = property.GetValue(actual, null);
if (!Equals(expectedValue, actualValue))
Assert.Fail("Property {0}.{1} does not match. Expected: {2} but was: {3}", property.DeclaringType.Name, property.Name, expectedValue, actualValue);
//……………………………….
}
如果用另一种方式来比较,那是什么?
【问题讨论】:
标签: c# asp.net-mvc unit-testing nunit fluent-assertions