我知道如何检查某个集合是否按某些属性排序:
Assert.That(actual, Is.Ordered.By("Foo"));
我如何断言实际按此特定顺序包含元素 (1,2,5,3,4)(无需编写自定义比较器)。
我知道如何检查某个集合是否按某些属性排序:
Assert.That(actual, Is.Ordered.By("Foo"));
我如何断言实际按此特定顺序包含元素 (1,2,5,3,4)(无需编写自定义比较器)。
利用
CollectionAssert.AreEqual(expectedIEnumerable, actualIEnumerable);
这将检查项目是否相等并且顺序相同。
我相当确定当您在集合上使用 Assert.That 时,您将获得集合断言功能。所以你可以说像
Assert.That(collection, Is.EqualTo(expectedCollection)); // Same order
或者
Assert.That(collection, Is.EquivalentTo(expectedCollection)); // Same item count
以及类似的东西
Assert.That(collection, Has.Count.EqualTo(expectedSize));
Has 关键字为您打开了特定于集合断言的内容,并且非常有用。