开发者

Creating a NUnit constraint meaning "{collection} does not contain {item}"

I'm struggling to make an assertion about the absence of a particular item in an enumeration. Specifically, this is what my test looks like:

// Take an item from a q开发者_JAVA技巧ueue 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));

Of course, Does.Not.Contain is not a valid nUnit constraint. How can I express it in a valid fluent syntax?


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

Only with NUnit 2.4 / 2.5


Use the CollectionAssert method:

CollectionAssert.DoesNotContain(schedule.PendingItems, item);


If you are using NUnit 2.4 / 2.5 you may checkout the collection constraints.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜