-
Couldn't load subscription status.
- Fork 233
Open
Labels
False PositiveRule IS triggered when it shouldn't be.Rule IS triggered when it shouldn't be.
Description
Description
In an async test method, S6966 is raised for Moq's Mock.Raise method, suggesting to use RaiseAsync instead.
RaiseAsync does not work for normal events and requires a Task-returning event signature instead: https://github.com/moq/moq/pull/1313.
I've seen that this rule has a list of exceptions for specific APIs, so maybe it would make sense to add this case to that list.
Repro steps
Consider this:
public interface IReproInterface
{
event EventHandler SomethingHappened;
}
public class Repro
{
[Test]
public async Task Test()
{
await Task.Yield();
var mock = new Mock<IReproInterface>();
mock.Raise(i => i.SomethingHappened += null, new EventArgs()); // "Await RaiseAsync instead"
}
}Expected behavior
Should not suggest RaiseAsync.
Actual behavior
Suggests to use RaiseAsync instead of Raise.
Known workarounds
--
Related information
- C#/VB.NET Plugins version: SonarLint 8.6.0.10679
- Visual Studio version: 17.12.0
- MSBuild / dotnet version: dotnet 9.0.100
- Operating System: Windows 11
Metadata
Metadata
Assignees
Labels
False PositiveRule IS triggered when it shouldn't be.Rule IS triggered when it shouldn't be.