【发布时间】:2022-07-17 20:20:06
【问题描述】:
我有一个收藏:
new[] { new { A = 5, PropIDontCareAbout = "XXX" }, new { A = 7, PropIDontCareAbout = "XXX" }, new { A = 9, PropIDontCareAbout = "XXX" } }
我想检查它至少包含new { A = 9 } 和new { A = 5 } 以任何顺序。
我可以使用ContainEquivalentOf,但我必须一个一个地做:
var actual = new[] {
new { A = 5, PropIDontCareAbout = "XXX" },
new { A = 7, PropIDontCareAbout = "XXX" },
new { A = 9, PropIDontCareAbout = "XXX" }
};
var expected = new [] { new { A = 5 }, new { A = 9 } };
foreach (var expectedItem in expected) {
actual.Should().ContainEquivalentOf(expectedItem);
}
更新:我不能使用Contains,因为它要求实际对象和预期对象具有相同的类型。
【问题讨论】: