[英]How to compare lists using fluent-assertions?
I want to compare a list of objects, ignoring the order of the objects in the list and only comparing some of the properties in the objects, currently I'm using the following code to perform this comparison: 我想比较一个对象列表,忽略列表中对象的顺序,只比较对象中的一些属性,目前我正在使用以下代码来执行此比较:
actual.Should().NotBeNull();
actual.Count.Should().Be(expected.Count);
//compare ignoring order
foreach (var exp in expected)
actual.Should().Contain(act =>
act.IndividualId.Equals(exp.IndividualId)
&& act.Email.Equals(exp.Email)
&& act.FirstName.Equals(exp.FirstName)
&& act.LastName.Equals(exp.LastName)
);
However this seems less than ideal, as when there is a failure you do not get a print out of the expected values. 然而,这似乎不太理想,因为当失败时,您没有得到预期值的打印。 Is there a built in mechanism for performing this comparison using fluent assertions? 是否有使用流畅断言执行此比较的内置机制?
Not right now. 不是现在。 We do have the new equivalency assertion syntax of FA 2.0, but that will also verify if the objects appear in the right order. 我们确实有FA 2.0的新等效断言语法,但这也将验证对象是否以正确的顺序出现。 For FA 2.1 I'm trying to support that, but I'm not sure yet if that will work. 对于FA 2.1,我试图支持这一点,但我不确定这是否有效。 It basically means it has to compare the entire object graph behind a collection item with the object graphs for each and every other item in the collection. 它基本上意味着它必须将集合项后面的整个对象图与集合中每个其他项的对象图进行比较。 Surely it will be rather slow. 肯定会很慢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.