FluentAssertion。如何验证两个列表中至少有一个相同的元素

问题描述:

默认情况下,我有预期的和实际的响应,看起来像JSON对象。在我的情况下有两个列表。我必须验证这两个列表在列表中有一个相同的元素。FluentAssertion。如何验证两个列表中至少有一个相同的元素

功能应该是这样的:

(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>接口(optionaly)和Equals方法(需要)。