Skip to content

Commit c31b5bf

Browse files
Bart KoelmanBart Koelman
authored andcommitted
AV1755: Do not report on test methods
Fixes #112
1 parent eb88164 commit c31b5bf

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/CSharpGuidelinesAnalyzer/CSharpGuidelinesAnalyzer.Test/Specs/Naming/SuffixAsyncMethodCorrectlySpecs.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,39 @@ static async Task Main(string[] args)
194194
VerifyGuidelineDiagnostic(source);
195195
}
196196

197+
[Fact]
198+
internal void When_test_method_name_does_not_end_with_Async_it_must_be_skipped()
199+
{
200+
// Arrange
201+
ParsedSourceCode source = new TypeSourceCodeBuilder()
202+
.Using(typeof(Task).Namespace)
203+
.InGlobalScope(@"
204+
namespace Xunit
205+
{
206+
public class FactAttribute : Attribute
207+
{
208+
}
209+
}
210+
211+
namespace App
212+
{
213+
using Xunit;
214+
215+
class UnitTests
216+
{
217+
[Fact]
218+
public async Task When_some_condition_it_must_work()
219+
{
220+
}
221+
}
222+
}
223+
")
224+
.Build();
225+
226+
// Act and assert
227+
VerifyGuidelineDiagnostic(source);
228+
}
229+
197230
protected override DiagnosticAnalyzer CreateAnalyzer()
198231
{
199232
return new SuffixAsyncMethodCorrectlyAnalyzer();

src/CSharpGuidelinesAnalyzer/CSharpGuidelinesAnalyzer/Rules/Naming/SuffixAsyncMethodCorrectlyAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static bool RequiresReport([NotNull] IMethodSymbol method, [NotNull] Com
6969
CancellationToken cancellationToken)
7070
{
7171
return method.IsAsync && !method.Name.EndsWith("Async", StringComparison.Ordinal) && !method.IsSynthesized() &&
72-
!method.IsEntryPoint(compilation, cancellationToken);
72+
!method.IsUnitTestMethod() && !method.IsEntryPoint(compilation, cancellationToken);
7373
}
7474

7575
private static void ReportAt([NotNull] IMethodSymbol method, [NotNull] Action<Diagnostic> reportDiagnostic)

0 commit comments

Comments
 (0)