I have a method named RenderContent which returns object[]
In my unit test, I need to assert that this array does not contain any objects of type VerifyRequest
At the moment, I'm using the following Assert
statement. Is there anything more concise?
Assert.That(
domain.RenderContent().OfType<VerifyRequest>().Count(),
Is.EqualTo(0)
);
I prefer to use fluent syntax. Note also that RenderContent returns object[]
, not IQueryable<object>
.
If you are using NUnit 2.5, you could use something like:
Assert.That(domain.RenderContent(), Has.None.InstanceOf<VerifyRequest>());
But I'm not sure if other unit test frameworks support this assert-style.
Although I don't know the exact NUnit syntax for IsFalse assertion, the best fit for this kind of test is the Any
extension method:
Assert.IsFalse(domain.RenderContent().OfType<VerifyRequest>().Any());
It might be tempting to use the Count
method, but Any
is more efficient, as it will break on the first occurrence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With