Skip to content

Commit bca736b

Browse files
authored
Merge pull request #118 from bkoelman/parameterized-test-methods
Adds detection of parameterized test methods
2 parents e7d5330 + 1b21986 commit bca736b

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,50 @@ public async Task When_some_condition_it_must_work()
227227
VerifyGuidelineDiagnostic(source);
228228
}
229229

230+
[Fact]
231+
internal void When_parameterized_test_method_name_does_not_end_with_Async_it_must_be_skipped()
232+
{
233+
// Arrange
234+
ParsedSourceCode source = new TypeSourceCodeBuilder()
235+
.Using(typeof(Task).Namespace)
236+
.InGlobalScope(@"
237+
namespace Xunit
238+
{
239+
public class TheoryAttribute : Attribute
240+
{
241+
}
242+
243+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
244+
public class InlineDataAttribute : Attribute
245+
{
246+
public InlineDataAttribute(params object[] data)
247+
{
248+
}
249+
}
250+
}
251+
252+
namespace App
253+
{
254+
using Xunit;
255+
256+
class UnitTests
257+
{
258+
[InlineData(""A"")]
259+
[InlineData(""B"")]
260+
[Theory]
261+
public async Task When_some_condition_it_must_work(string value)
262+
{
263+
_ = value;
264+
}
265+
}
266+
}
267+
")
268+
.Build();
269+
270+
// Act and assert
271+
VerifyGuidelineDiagnostic(source);
272+
}
273+
230274
protected override DiagnosticAnalyzer CreateAnalyzer()
231275
{
232276
return new SuffixAsyncMethodCorrectlyAnalyzer();

src/CSharpGuidelinesAnalyzer/CSharpGuidelinesAnalyzer/Extensions/SymbolExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ namespace CSharpGuidelinesAnalyzer.Extensions
1515
internal static class SymbolExtensions
1616
{
1717
[ItemNotNull]
18-
private static readonly ImmutableArray<string> UnitTestFrameworkMethodAttributeNames =
19-
ImmutableArray.Create("Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute", "Xunit.FactAttribute",
20-
"NUnit.Framework.TestAttribute", "MbUnit.Framework.TestAttribute");
18+
private static readonly ImmutableArray<string> UnitTestFrameworkMethodAttributeNames = ImmutableArray.Create(
19+
"Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute",
20+
"Microsoft.VisualStudio.TestTools.UnitTesting.DataTestMethod", "Xunit.FactAttribute", "Xunit.TheoryAttribute",
21+
"NUnit.Framework.TestAttribute", "NUnit.Framework.TestCaseAttribute", "MbUnit.Framework.TestAttribute");
2122

2223
[NotNull]
2324
[ItemNotNull]

0 commit comments

Comments
 (0)