Skip to content

Commit 92f64f1

Browse files
BoukeJohanLarsson
authored andcommitted
Opt-out of Moq's Verify() / Setup() in IDISP013
1 parent 6b35c3a commit 92f64f1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

IDisposableAnalyzers.Test/IDISP013AwaitInUsingTests/Valid.Ignore.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,34 @@ public void M()
3232
""";
3333
RoslynAssert.Valid(Analyzer, code);
3434
}
35+
36+
[Test]
37+
public static void MoqSetupVerifyAsync()
38+
{
39+
var code = @"
40+
namespace N
41+
{
42+
using System;
43+
using System.IO;
44+
using System.Threading;
45+
using Moq;
46+
47+
public class C
48+
{
49+
public void M()
50+
{
51+
using (var stream = File.OpenRead(string.Empty))
52+
{
53+
var mock = new Mock<Stream>();
54+
mock.Setup(x => x.ReadAsync(It.IsAny<Memory<byte>>(), It.IsAny<CancellationToken>()))
55+
.ReturnsAsync(0);
56+
mock.Verify(x => x.ReadAsync(It.IsAny<Memory<byte>>(), It.IsAny<CancellationToken>()));
57+
}
58+
}
59+
}
60+
}";
61+
62+
RoslynAssert.Valid(Analyzer, code);
63+
}
3564
}
3665
}

IDisposableAnalyzers/Analyzers/ReturnValueAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static bool ShouldAwait(SyntaxNodeAnalysisContext context, ExpressionSyntax retu
136136
{
137137
if (returnValue.TryFirstAncestor(out InvocationExpressionSyntax? ancestor) &&
138138
ancestor.TryGetMethodName(out var ancestorName) &&
139-
ancestorName == "ThrowsAsync")
139+
ancestorName is "ThrowsAsync" or "Setup" or "Verify")
140140
{
141141
return false;
142142
}

0 commit comments

Comments
 (0)