简体   繁体   English

如何使用流畅断言比较列表?

[英]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.

相关问题 如何使用流畅断言组合集合和属性断言? - How to combine collection and property assertions using fluent-assertions? 如何使用流畅的断言断言集合中的所有项目? - How to assert all items in a collection using fluent-assertions? 如何使用流利断言断言一个集合是其他集合的子集合? - How to assert a collection is a child of other collection using fluent-assertions? 如果使用Fluent断言顺序不同,如何断言两个列表是不等效的 - How to assert two lists are not equivalent if in different order using Fluent Assertions 流利的评估ShouldRaisePropertyChangeFor不适用于异步任务吗? - Fluent-ASsertions ShouldRaisePropertyChangeFor does not work for async Tasks? Fluent断言:大致比较列表中存储的对象的属性 - Fluent Assertions: Approximately compare the properties of objects stored in Lists 通过使用Fluent断言在嵌套列表中包含属性来测试列表是否等效 - Testing list equivalency by including properties in nested lists using Fluent Assertions 如何检查列表是使用Fluent断言进行排序的 - How to check a list is ordered using Fluent Assertions Fluent断言将字符串与Guid进行比较 - Fluent Assertions compare string to Guid 如何在流畅的断言中比较null和string.Empty(或“”)? - How can I compare null and string.Empty (or “”) in fluent assertions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM