创建NUnit约束意味着"{collection}不包含{item}"

Hum*_*rto 31 c# nunit

我正在努力做出关于枚举中缺少特定项目的断言.具体来说,这就是我的测试结果:

// Take an item from a queue of scheduled items...
ItemQueue pendingQueue = schedule.PendingItems; // PendingItems is an IEnumerable<int>
int item = pendingQueue.FirstItem;

// ...process the item...
processor.DoSomethingWith(item);

// ...and the schedule must not contain the item anymore:
Assert.That(schedule.PendingItems, Does.Not.Contain(item));
Run Code Online (Sandbox Code Playgroud)

当然,Does.Not.Contain不是有效的nUnit约束.如何用有效的流利语法表达它?

gco*_*res 48

Assert.That(schedule.PendingItems, Has.No.Member(item))
Run Code Online (Sandbox Code Playgroud)

仅适用于NUnit 2.4/2.5


Rok*_*iša 13

使用CollectionAssert方法:

CollectionAssert.DoesNotContain(schedule.PendingItems, item);
Run Code Online (Sandbox Code Playgroud)


Dar*_*rov 5

如果您使用的是NUnit 2.4/2.5,则可以检查集合约束.