Skip to content

Commit

Permalink
Merge pull request #686 from manfred-brands/issue685_TestCaseSource
Browse files Browse the repository at this point in the history
Fix case where TestCaseSource and no CancellationToken parameter
  • Loading branch information
mikkelbu authored Jan 30, 2024
2 parents 9330fc4 + 09b905c commit 16f640e
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 16f640e

Please sign in to comment.