diff --git a/Build/.nuke/build.schema.json b/Build/.nuke/build.schema.json index 6bd7ef6..22baf5a 100644 --- a/Build/.nuke/build.schema.json +++ b/Build/.nuke/build.schema.json @@ -65,6 +65,12 @@ "type": "boolean", "description": "Shows the execution plan (HTML)" }, + "PreReleaseFilter": { + "type": "array", + "items": { + "type": "string" + } + }, "Profile": { "type": "array", "description": "Defines the profiles to load", @@ -99,8 +105,10 @@ "Build", "Clean", "Compile", + "GitPreRelease", "GitRelease", "Pack", + "PrePack", "Release", "Sign", "Test" @@ -120,8 +128,10 @@ "Build", "Clean", "Compile", + "GitPreRelease", "GitRelease", "Pack", + "PrePack", "Release", "Sign", "Test" diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c42f0..9c503c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update to support target `net48` and `net8.0`. - Update `TestAttributeService` to convert `TestCaseSourceAttribute` to `TestCaseAttribute`. - Update `TestCaseSourceService` to support multiple parameters. +- Update `TestCaseSourceService` to support `TestCaseData`. ### Added - Add `TestCaseSourceService` with `TestCaseSourceAttribute` implementation. ### Tests diff --git a/Directory.Build.props b/Directory.Build.props index 35c490e..f8afd83 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.4.0-alpha.1 + 1.4.0-beta \ No newline at end of file diff --git a/SampleTest.Tests/TestsCaseSource.cs b/SampleTest.Tests/TestsCaseSource.cs index 0af2182..6ab4719 100644 --- a/SampleTest.Tests/TestsCaseSource.cs +++ b/SampleTest.Tests/TestsCaseSource.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System.Collections; using System.Collections.Generic; namespace SampleTest.Tests @@ -40,6 +41,15 @@ public void CasesSourceMethodWithParametersTest(int i) Assert.True(i > 0); } + public class AnotherClass + { + public static object[] CasesSource = + { + new object[] { 1, 2, 3 }, + new object[] { 2, 3, 4 }, + new object[] { 3, 4, 5 } + }; + } [TestCaseSource(typeof(AnotherClass), nameof(AnotherClass.CasesSource))] public void CasesSourceAnotherClassTest(int i, int j, int k) { @@ -47,14 +57,21 @@ public void CasesSourceAnotherClassTest(int i, int j, int k) Assert.True(j > 0); Assert.True(k > 0); } - public class AnotherClass + + public static IEnumerable TestCaseDatas { - public static object[] CasesSource = + get { - new object[] { 1, 2, 3 }, - new object[] { 2, 3, 4 }, - new object[] { 3, 4, 5 } - }; + yield return new TestCaseData(0).Returns(false); + yield return new TestCaseData(1).Returns(true); + yield return new TestCaseData(2).Returns(true); + yield return new TestCaseData(3).Returns(true); + } + } + [TestCaseSource(nameof(TestCaseDatas))] + public bool CasesSourceTestCaseDataTest(int i) + { + return i > 0; } } } \ No newline at end of file diff --git a/ricaun.NUnit.Tests/NUnitTests.cs b/ricaun.NUnit.Tests/NUnitTests.cs index 32ced77..428f161 100644 --- a/ricaun.NUnit.Tests/NUnitTests.cs +++ b/ricaun.NUnit.Tests/NUnitTests.cs @@ -303,8 +303,8 @@ public void TestAssembly_Parameters() [TestCase("*.MultipleTest.*", 2)] [TestCase("*AbstractTest?*", 4)] [TestCase("*Abstract*", 4)] - [TestCase("*.TestsCaseSource.*", 13)] - [TestCase("*", 73)] + [TestCase("*.TestsCaseSource.*", 17)] + [TestCase("*", 77)] public void TestAssembly_Filter(string testName, int numberOfTests) { TestEngineFilter.Add(testName); diff --git a/ricaun.NUnit/Services/TestCaseSourceService.cs b/ricaun.NUnit/Services/TestCaseSourceService.cs index 82c01c0..fe5e708 100644 --- a/ricaun.NUnit/Services/TestCaseSourceService.cs +++ b/ricaun.NUnit/Services/TestCaseSourceService.cs @@ -28,16 +28,24 @@ internal static IEnumerable GetTestCasesFromSource(MethodInfo { foreach (object item in source) { + var testCase = new TestCaseAttribute(item); if (item is Array array) { var args = new object[array.Length]; for (var i = 0; i < array.Length; i++) args[i] = array.GetValue(i); - attributes.Add(new TestCaseAttribute(args)); - continue; + testCase = new TestCaseAttribute(args); } - attributes.Add(new TestCaseAttribute(item)); + else if (item is TestCaseData testCaseData) + { + testCase = new TestCaseAttribute(testCaseData.Arguments); + + if (testCaseData.HasExpectedResult) + testCase.ExpectedResult = testCaseData.ExpectedResult; + } + + attributes.Add(testCase); } } }