NUnit2044
Non-delegate actual parameter
Topic | Value |
---|---|
Id | NUnit2044 |
Severity | Error |
Enabled | True |
Category | Assertion |
Code | DelegateRequiredAnalyzer |
Description
The actual argument needs to be evaluated by the Assert to catch any exceptions.
Motivation
In order for the Assert.That
to catch an exception or a timeout, the code must be
a delegate so it can be evaluated by the method. If the parameter is not a
delegate, it will be evaluated before the call to Assert.That
and stop further
execution.
How to fix violations
Convert the call into a delegate using a lambda expression or method group.
Configure severity
Via ruleset file
Configure the severity per project, for more info see MSDN.
Via .editorconfig file
# NUnit2044: Non-delegate actual parameter
dotnet_diagnostic.NUnit2044.severity = chosenSeverity
where chosenSeverity
can be one of none
, silent
, suggestion
, warning
, or error
.
Via #pragma directive
#pragma warning disable NUnit2044 // Non-delegate actual parameter
Code violating the rule here
#pragma warning restore NUnit2044 // Non-delegate actual parameter
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2044 // Non-delegate actual parameter
Via attribute [SuppressMessage]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2044:Non-delegate actual parameter",
Justification = "Reason...")]