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

Viewed 9543

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?

3 Answers
Related