Is there a way to check if an object does NOT contain an item in NUnit? The NUnit.Framework.Assert.Contains()
method checks if an item is contained, but I am looking for the opposite here. A lot of methods have a negative counterpart (like Assert.NotNull()
, Assert.AreNotEqual()
and Assert.DoesNotThrow()
), but Contains()
Seems to be lacking such an opposite method.
The only way I found is checking it manually using Assert.That()
, but that is a little bit clunky and doesn't read as well.
Assert.That(!result.Dependencies.Contains<string>("tableName"));
I believe these should work:
Assert.That(result.Dependencies, Does.Not.Contain("tableName"));
Assert.That(result.Dependencies, Has.None.EqualTo("tableName"));
In general, the framework has not added new "Classic" assertions for some years. DoesNotContain would be easy to implement, so you can always ask the project for it if you prefer the older syntax.
@Commenters... The problem with Assert.That(bool condition)
is that it doesn't give a very good error message, so I can understand why @Axel doesn't want to use it. Of course, it can be used with an error message specified, but that's more typing. :-)