diff --git a/src/nunit.analyzers.tests/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzerTests.cs b/src/nunit.analyzers.tests/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzerTests.cs index 4a5dee71..66564bcc 100644 --- a/src/nunit.analyzers.tests/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzerTests.cs +++ b/src/nunit.analyzers.tests/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzerTests.cs @@ -761,6 +761,33 @@ static IEnumerable TestData(int first, int second, int third) RoslynAssert.Valid(analyzer, testCode); } + [Test] + public void AnalyzeWhenNumberOfParametersMatchNoImplicitlySuppliedCancellationTokenParameter() + { + var testCode = TestUtility.WrapClassInNamespaceAndAddUsing(@" + [TestFixture] + public class AnalyzeWhenNumberOfParametersMatch + { + [TestCaseSource(nameof(TestData), new object[] { 1, 3, 5 })] + [CancelAfter(10)] + public void ShortName(int number) + { + if (TestContext.CurrentContext.CancellationToken.IsCancellationRequested) + Assert.Ignore(""Cancelled""); + Assert.That(number, Is.GreaterThanOrEqualTo(0)); + } + + static IEnumerable TestData(int first, int second, int third) + { + yield return first; + yield return second; + yield return third; + } + }", additionalUsings: "using System.Collections.Generic;"); + + RoslynAssert.Valid(analyzer, testCode); + } + [Test] public void AnalyzeWhenNumberOfParametersDoesNotMatchNoParametersExpectedNoImplicitSuppliedCancellationToken() { diff --git a/src/nunit.analyzers/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzer.cs b/src/nunit.analyzers/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzer.cs index 8a3cd697..f4593d42 100644 --- a/src/nunit.analyzers/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzer.cs +++ b/src/nunit.analyzers/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzer.cs @@ -268,13 +268,13 @@ private static void AnalyzeAttribute( } else { - if (methodRequiredParameters + methodOptionalParameters != (hasCancelAfterAttribute ? 2 : 1)) + if (methodRequiredParameters != 1) { context.ReportDiagnostic(Diagnostic.Create( mismatchInNumberOfTestMethodParameters, syntaxNode.GetLocation(), 1, - methodRequiredParameters + methodOptionalParameters)); + methodRequiredParameters)); } else {