CollectionAssert.Contains()作为NUnit的Assert.Contains()的替代品

时间:2015-09-04 16:07:04

标签: c# testing nunit

我正在使用Visual Studio项目中的TestManager替换NUnit。 NUnit具有以下断言:

  • template
  • Assert.Contains(string, collection)

我在TestManager中使用以下内容:

  • Assert.That(collection, Has.No.Member(string))
  • CollectionAssert.Contains(collection, string)

我正在寻找替换

的方法

CollectionAssert.DoesNotContain(collection, string)Assert.IsEmpty(collection)

我可以使用Assert.IsNotEmpty(collection)但是宁愿在收集上有更坚实的反映。

1 个答案:

答案 0 :(得分:1)

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");