-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Milestone
Description
I've been rewriting all our tests that use Assert.Multiple to Assert.EnterMultipleScope but came across this issue that makes it currently impossible.
Given the following old code:
var restResponse = new RestResponse();
Assert.Multiple(() =>
{
Assert.That(restResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(restResponse.Content, Is.Not.Null);
}
// restResponse.Content is definitely not null here
Assert.That(restResponse.Content.ToString(), Is.EqualTo("Test"));And the code with EnterMultipleScope:
var restResponse = new RestResponse();
using (Assert.EnterMultipleScope())
{
Assert.That(restResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(restResponse.Content, Is.Not.Null);
}
// restResponse.Content may be null here
Assert.That(restResponse.Content.ToString(), Is.EqualTo("Test"));In the old version, the last assert does not produce a warning, because the analyzer knows that restResponse.Content is not null, or it would have failed earlier. In the newer version, it does produce a warning because it apparently does not know that restResponse.Content is definitely not null.
Both should work the same in detecting whether something can be null further on in the test.
Metadata
Metadata
Assignees
Labels
No labels