docs/articles/nunit-analyzers/NUnit2019.md
| Topic | Value |
|---|---|
| Id | NUnit2019 |
| Severity | Info |
| Enabled | True |
| Category | Assertion |
| Code | ClassicModelAssertUsageAnalyzer |
Consider using the constraint model, Assert.That(expr, Is.Not.Null), instead of the classic model,
ClassicAssert.IsNotNull(expr).
The classic Assert model contains less flexibility than the constraint model,
so this analyzer marks usages of ClassicAssert.IsNotNull from the classic Assert model.
[Test]
public void Test()
{
object obj = null;
ClassicAssert.IsNotNull(obj);
}
The analyzer comes with a code fix that will replace ClassicAssert.IsNotNull(expression) with
Assert.That(expression, Is.Not.Null). So the code block above will be changed into.
[Test]
public void Test()
{
object obj = null;
Assert.That(obj, Is.Not.Null);
}
Configure the severity per project, for more info see MSDN.
# NUnit2019: Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.IsNotNull(expr)
dotnet_diagnostic.NUnit2019.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit2019 // Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.IsNotNull(expr)
Code violating the rule here
#pragma warning restore NUnit2019 // Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.IsNotNull(expr)
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2019 // Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.IsNotNull(expr)
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2019:Consider using Assert.That(expr, Is.Not.Null) instead of ClassicAssert.IsNotNull(expr)",
Justification = "Reason...")]