【问题标题】:FluentAssertion. How to verify that two lists have at least one the same element流畅的断言。如何验证两个列表至少有一个相同的元素
【发布时间】:2017-09-10 11:01:41
【问题描述】:
默认情况下,我的预期和实际响应看起来像 JSON 对象。就我而言,有两个列表。我必须验证这两个列表在列表一中是否具有相同的元素。
函数应该是这样的:
(expectedResponse, actualResponse) => ((List<Question>)actualResponse.Body).Should()
.NotIntersectWith(((List<Question>)expectedResponse.Body))
【问题讨论】:
标签:
c#
json
fluent-assertions
【解决方案1】:
从他们的wiki,你可以使用IntersectWith方法:
IEnumerable otherCollection = new[] { 1, 2, 5, 8, 1 };
IEnumerable anotherCollection = new[] { 10, 20, 50, 80, 10 };
collection.Should().IntersectWith(otherCollection);
确保集合中的对象正确实现IEquatable<T> 接口(可选)和Equals 方法(必需)。