【发布时间】:2022-05-01 16:09:11
【问题描述】:
我确定我错过了明显的...
假设我们有:
[Fact]
public void SomeTest()
{
var a = new { SomeProp = "hello", AnotherProp = 9 };
var b = new { SomeProp = "hello" };
var c = new { AnotherProp = 9 };
var d = new { SomeProp = "hello", AnotherProp = 9 };
}
检查所有属性是否匹配的正确断言是什么(例如 a 和 d 将返回 true,但所有其他组合将返回 false?
目前,我正在做等效性检查,但必须双向进行吗?例如
a.Should().BeEquivalentTo(d);
d.Should().BeEquivalentTo(a);
如果文档中明确定义了这一点,请原谅我......我找不到它:/
【问题讨论】:
-
除非我误解了您的问题,否则
a.Should().BeEquivalentTo(d);就是这样做的。 -
这只检查
d的属性在a中是否具有匹配的属性。但它不会反过来检查。试试看,你会发现`a.Should().BeEquivalentTo(b);`和`a.Should().BeEquivalentTo(c);`也通过了
标签: c# .net-core .net-standard fluent-assertions