Skip to content

Commit

Permalink
Opt-out of Moq's Verify() / Setup() in IDISP013
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke authored and JohanLarsson committed Mar 3, 2024
1 parent 6b35c3a commit 92f64f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,34 @@ public void M()
""";
RoslynAssert.Valid(Analyzer, code);
}

[Test]
public static void MoqSetupVerifyAsync()
{
var code = @"
namespace N
{
using System;
using System.IO;
using System.Threading;
using Moq;
public class C
{
public void M()
{
using (var stream = File.OpenRead(string.Empty))
{
var mock = new Mock<Stream>();
mock.Setup(x => x.ReadAsync(It.IsAny<Memory<byte>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(0);
mock.Verify(x => x.ReadAsync(It.IsAny<Memory<byte>>(), It.IsAny<CancellationToken>()));
}
}
}
}";

RoslynAssert.Valid(Analyzer, code);
}
}
}
2 changes: 1 addition & 1 deletion IDisposableAnalyzers/Analyzers/ReturnValueAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static bool ShouldAwait(SyntaxNodeAnalysisContext context, ExpressionSyntax retu
{
if (returnValue.TryFirstAncestor(out InvocationExpressionSyntax? ancestor) &&
ancestor.TryGetMethodName(out var ancestorName) &&
ancestorName == "ThrowsAsync")
ancestorName is "ThrowsAsync" or "Setup" or "Verify")
{
return false;
}
Expand Down

0 comments on commit 92f64f1

Please sign in to comment.