问题描述
使用 FluentAssertions v5.10.3,我试图比较两个具有某些匹配属性的不同 对象类型。像这样:
[Fact]
public void Should_not_be_equivalent()
{
var actual = new ActualClass();
var expected = new ExpectedClass();
actual.Should().BeEquivalentTo(expected); // 1. Does not fail here
}
[Fact]
public void Should_not_be_equivalent_too()
{
var actual = new ActualClass();
var expected = new ExpectedClass();
expected.Should().BeEquivalentTo(actual); // 2. Fails here
}
class ActualClass
{
public string Property1 = "Property1";
public string Property2 = "Property2";
public string Property3 = "Property3";
}
class ExpectedClass
{
public string Property1 = "Property1";
public string Property2 = "Property2";
}
我希望这两个测试都失败,因为在实际类中有一个额外的属性,它甚至分配了一些值。但只有第二次测试失败。
这是预期的行为吗?这有什么特殊原因吗? 比较这些对象的最佳方法是什么?
UPD:FluentAssertions github 上有一个悬而未决的问题:https://github.com/fluentassertions/fluentassertions/issues/1249 与此问题相关,实际上回答了大部分问题,甚至包含类似的复制代码。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)