Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.42 KB

File metadata and controls

54 lines (41 loc) · 1.42 KB

NS5002

CheckId NS5002
Category Usage

Cause

Usage of async callback in Received.InOrder method.

Rule description

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.

How to fix violations

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();
})

How to suppress violations

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.