Problem Statement
Hi,
Assert.That().IsNotNull() don't suppress nullable warnings for some code after the Assert.
The following code gives a warning CS8629 "Nullable value type may be null." when the Id is guaranteed to be not null after the Assert.
Proposed Solution
[Test]
[Arguments(1)]
public async Task CheckNull(int? id)
{
var value = new
{
Id = id
};
await Assert.That(value.Id)
.IsNotNull();
await Assert.That(value.Id.Value)
.EqualTo(0);
}
Alternatives Considered
For example with an extra if ... is not null, the compiler can suppress the warning :
[Test]
[Arguments(1)]
public async Task CheckNull(int? id)
{
var value = new
{
Id = id
};
await Assert.That(value.Id)
.IsNotNull();
if (value.Id is not null)
{
await Assert.That(value.Id.Value)
.EqualTo(0);
}
}
Feature Category
Other
How important is this feature to you?
Nice to have - would improve my experience
Additional Context
No response
Contribution
Problem Statement
Hi,
Assert.That().IsNotNull()don't suppress nullable warnings for some code after the Assert.The following code gives a warning CS8629 "Nullable value type may be null." when the Id is guaranteed to be not null after the Assert.
Proposed Solution
Alternatives Considered
For example with an extra
if ... is not null, the compiler can suppress the warning :Feature Category
Other
How important is this feature to you?
Nice to have - would improve my experience
Additional Context
No response
Contribution