我在我的 Visual Studio 项目中用 TestManager 替换了 NUnit。 NUnit 具有以下断言:
-
Assert.Contains(string, collection)
-
Assert.That(collection, Has.No.Member(string))
我正在为 TestManager 使用以下内容:
-
CollectionAssert.Contains(collection, string)
-
CollectionAssert.DoesNotContain(collection, string)
我正在寻找一种替代方法
Assert.IsEmpty(collection)
和 Assert.IsNotEmpty(collection)
我可以使用 CollectionAssert.DoesNotContain(collection, new List<string>())
但宁愿有一些更扎实的东西反射(reflect)在收藏上。
最佳答案
LINQ 通常适用于检查集合。
Assert.IsFalse(collection.Any()); // Assert.IsEmpty(collection)
Assert.IsTrue(collection.Any()); // Assert.IsNotEmpty(collection)
如果您正在寻找更流畅的界面 - 请考虑 FluentAssertions NuGet .
collection.Should().BeEmpty("because there are no doors");
关于c# - CollectionAssert.Contains() 作为 NUnit 的 Assert.Contains() 的替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32402307/