流利的断言.如何验证两个列表是否至少有一个相同的元素



我有预期和实际的响应,默认情况下看起来像JSON对象。就我而言,有两个列表。我必须验证这两个列表是否在列表 1 中具有相同的元素。

函数应如下所示:

(expectedResponse, actualResponse) => ((List<Question>)actualResponse.Body).Should()
                        .NotIntersectWith(((List<Question>)expectedResponse.Body))

在他们的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方法(必需(。

最新更新