Skip to content

Can NotBeNull() keep the property type? #1748

Answered by dennisdoomen
mu88 asked this question in Q&A
Discussion options

You must be logged in to vote

Because of limitations of the compiler, we cannot define a generic Should extension method on T and still have more specific extension method for types like IEnumerable<T>, etc. That's why your example is using the non-generic ObjectAssertions.

There's a rather ugly workaround:

testee.Should().NotBeNull().And.Subject.As<HttpResponseMessage>().StatusCode.Should().Be(HttpStatusCode.Accepted);

But my recommendation is to replace this call with:

testee.Should().BeEquivalentTo(new
{
    StatusCode = HttpStatusCode.Accepted
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mu88
Comment options

Answer selected by mu88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants