Skip to content

Commit

Permalink
Fix case where TestCaseSource and no CancellationToken parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-brands committed Jan 30, 2024
1 parent 9330fc4 commit 09b905c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,33 @@ static IEnumerable<int> 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<int> 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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 09b905c

Please sign in to comment.