CheckId | NS5002 |
Category | Usage |
Usage of async callback in Received.InOrder
method.
A violation of this rule occurs when async callback is used in Received.InOrder
method. Received.InOrder
is used to specify calls which should be received by one or more substitutes. Running/awaiting these calls is not required for this, and can cause some problems as described in issue #604.
To fix a violation of this rule, remove async modifier from Received.InOrder
callback.
For example:
// Incorrect:
Received.InOrder(async () =>
{
await sub.Received().Bar();
})
// Correct:
Received.InOrder(() =>
{
sub.Bar();
})
This warning can be suppressed by disabling the warning in the ruleset file for the project. The warning can also be suppressed programmatically for an assembly:
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "NS5002:Async callback used in Received.InOrder method.", Justification = "Reviewed")]
Or for a specific code block:
#pragma warning disable NS5002 // Async callback used in Received.InOrder method.
// the code which produces warning
#pragma warning restore NS5002 // Async callback used in Received.InOrder method.