Skip to content

Commit

Permalink
Add a shorthand for testplan's IsMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
delatrie committed Oct 4, 2023
1 parent b6382de commit 1210224
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
7 changes: 1 addition & 6 deletions Allure.NUnit/Core/AllureNUnitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ void UpdateTestDataFromAllureAttributes(TestResult testResult)
}

static bool IsSelectedByTestPlan(TestResult testResult) =>
TestPlan.Value.IsMatch(
testResult.fullName,
AllureTestPlan.GetAllureId(
testResult.labels ?? Enumerable.Empty<Label>()
)
);
TestPlan.Value.IsMatch(testResult);

IEnumerable<AllureTestCaseAttribute> IterateAllAllureAttribites() =>
this._test.Method
Expand Down
36 changes: 36 additions & 0 deletions Allure.Net.Commons.Tests/SelectiveRunTests/TestPlanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,42 @@ bool expectedMatch
);
}

[Test]
public void TestResultMatchShorthandTest(
[Values(
"[]",
"[{\"id\": \"100\"}]",
"[{\"selector\": \"a\"}]",
"[{\"selector\": \"a\", \"id\": \"100\"}]",
"[{\"id\": \"100\"}, {\"id\": \"101\"}]",
"[{\"selector\": \"a\"}, {\"selector\": \"b\"}]",
"[{\"id\": \"100\"}, {\"selector\": \"a\"}]",
"[{\"selector\": \"a\", \"id\": \"100\"}, {\"selector\": \"b\", \"id\": \"101\"}]"
)] string testPlanItemsJson,
[Values("a", "b", "c")] string fullNameOfTestCase,
[Values("100", "101", "102")] string allureIdOfTestCase
)
{
var testResult = new TestResult
{
fullName = fullNameOfTestCase,
labels = allureIdOfTestCase is null ? new() : new()
{
new() { name = "ALLURE_ID", value = allureIdOfTestCase }
}
};
var testPlan = AllureTestPlan.FromJson(
$"{{\"tests\": {testPlanItemsJson}}}"
);

Assert.That(
testPlan.IsMatch(testResult),
Is.EqualTo(
testPlan.IsMatch(fullNameOfTestCase, allureIdOfTestCase)
)
);
}

[TestCase(new string[] { }, null)]
[TestCase(new[] { "ALLURE_ID", "100" }, "100")]
[TestCase(new[] { "l1", "v1" }, null)]
Expand Down
10 changes: 10 additions & 0 deletions Allure.Net.Commons/TestPlan/AllureTestPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public bool IsMatch(string fullName, string? allureId) =>
|| this.IsFullNameMatch(fullName)
|| this.IsAllureIdMatch(allureId);

/// <summary>
/// A shorthand for <see cref="IsMatch(string, string?)"/> with the
/// fullName and the allure id taken from the provided test result.
/// </summary>
public bool IsMatch(TestResult testResult) =>
this.IsMatch(
testResult.fullName,
GetAllureId(testResult.labels)
);

/// <summary>
/// Creates the testplan from a JSON string.
/// </summary>
Expand Down

0 comments on commit 1210224

Please sign in to comment.