From ec96884f8d448eff488489ec2100961eb4674573 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Sat, 13 Aug 2022 23:05:17 -0700 Subject: [PATCH] Support NUnit TheoryAttribute Fixes https://github.com/OmniSharp/omnisharp-roslyn/issues/2379. --- .../TestFrameworks/NUnitTestFramework.cs | 3 ++- .../test-projects/NUnitTestProject/TestProgram.cs | 13 +++++++++++++ tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.DotNetTest/TestFrameworks/NUnitTestFramework.cs b/src/OmniSharp.DotNetTest/TestFrameworks/NUnitTestFramework.cs index 591fe564d8..aae7488fed 100644 --- a/src/OmniSharp.DotNetTest/TestFrameworks/NUnitTestFramework.cs +++ b/src/OmniSharp.DotNetTest/TestFrameworks/NUnitTestFramework.cs @@ -10,7 +10,8 @@ protected override bool IsTestAttributeName(string typeName) { return typeName == "NUnit.Framework.TestAttribute" || typeName == "NUnit.Framework.TestCaseAttribute" - || typeName == "NUnit.Framework.TestCaseSourceAttribute"; + || typeName == "NUnit.Framework.TestCaseSourceAttribute" + || typeName == "NUnit.Framework.Theory"; } } } diff --git a/test-assets/test-projects/NUnitTestProject/TestProgram.cs b/test-assets/test-projects/NUnitTestProject/TestProgram.cs index f70d2165bd..8e7e162157 100644 --- a/test-assets/test-projects/NUnitTestProject/TestProgram.cs +++ b/test-assets/test-projects/NUnitTestProject/TestProgram.cs @@ -86,4 +86,17 @@ public void M() } } + + [TestFixture(typeof(int))] + public class TheorySampleTestsGeneric + { + [Datapoint] + public int[] ArrayInt = { 0, 1, 2, 3 }; + + [Theory] + public void TestGenericForArbitraryArray(T[] array) + { + Assert.That(array.Length, Is.EqualTo(4)); + } + } } diff --git a/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs index 7de1a84c62..359bd7ac49 100644 --- a/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs @@ -222,6 +222,18 @@ public async Task RunNunitTypedTestRunsTwice() Assert.Equal(2, response.Results.Length); } + [Fact] + public async Task RunNunitTheoryTest() + { + var response = await RunDotNetTestAsync( + NUnitTestProject, + methodName: "Main.Test.TheorySampleTestsGeneric`1.TestGenericForArbitraryArray", + testFramework: "nunit", + shouldPass: true); + + Assert.Single(response.Results); + } + [Fact] public async Task RunMSTestTest() {