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

问题描述 投票:-1回答:1

我目前正在使用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);
    //……………………………….
}

如果使用其他方式进行比较,那是什么?

我目前正在使用FluentAssertion比较2个对象。我真的很想知道它用来比较的方式是什么?然后使用反射,然后像这样循环所有道具?公共静态无效...

c# asp.net-mvc unit-testing nunit fluent-assertions
1个回答
1
投票

我建议您read the documentation了解它使用的算法。但是我可以告诉你,它充满了反思。

© www.soinside.com 2019 - 2024. All rights reserved.