tags:

views:

36

answers:

2

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

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

+1  A: 

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

Darin Dimitrov
Has.None.EqualTo(item) solved my problem. Thanks!
Humberto
+4  A: 
Assert.That( schedule.PendingItems, Has.No.Member(item)

Only with NUnit 2.4 / 2.5

gcores
Works fine, thank you.
Humberto