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

C# 创建NUnit约束意味着;{collection}不包含{item}";,c#,nunit,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.DoSom

我很难断言枚举中没有特定项。具体来说,我的测试是这样的:

// 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));
//从计划项目队列中获取项目。。。
ItemQueue pendingQueue=schedule.PendingItems;//PendingItems是一个IEnumerable
int item=pendingQueue.FirstItem;
//…处理项目。。。
处理器。带(项目)的DoSomethingWith;
//…并且计划中不得再包含该项目:
Assert.That(schedule.PendingItems,Not.Contain(item));

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

如果您使用的是NUnit 2.4/2.5,您可以签出

只有使用NUnit 2.4/2.5时,才能使用以下方法:

Assert.That(schedule.PendingItems, Has.No.Member(item))
CollectionAssert.DoesNotContain(schedule.PendingItems, item);