diff --git a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs index 20314bd619..84f7e8633c 100644 --- a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs +++ b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs @@ -50,9 +50,11 @@ public static class V2 public const string GetTestStartInfo = "/v2/getteststartinfo"; public const string RunTest = "/v2/runtest"; + public const string RunAllTestsInClass = "/v2/runtestsinclass"; public const string DebugTestGetStartInfo = "/v2/debugtest/getstartinfo"; public const string DebugTestLaunch = "/v2/debugtest/launch"; public const string DebugTestStop = "/v2/debugtest/stop"; + public const string DebugTestsInClassGetStartInfo = "/v2/debugtestsinclass/getstartinfo"; } } } diff --git a/src/OmniSharp.DotNetTest/DebugSessionManager.cs b/src/OmniSharp.DotNetTest/DebugSessionManager.cs index 1c9354c402..0f4ba7a921 100644 --- a/src/OmniSharp.DotNetTest/DebugSessionManager.cs +++ b/src/OmniSharp.DotNetTest/DebugSessionManager.cs @@ -78,10 +78,13 @@ public void EndSession() } public Task DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) + => DebugGetStartInfoAsync(new string[] { methodName }, testFrameworkName, targetFrameworkVersion, cancellationToken); + + public Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) { VerifySession(isStarted: true); - return _testManager.DebugGetStartInfoAsync(methodName, testFrameworkName, targetFrameworkVersion, cancellationToken); + return _testManager.DebugGetStartInfoAsync(methodNames, testFrameworkName, targetFrameworkVersion, cancellationToken); } public async Task DebugLaunchAsync(int targetProcessId) diff --git a/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs b/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs new file mode 100644 index 0000000000..e28fc9a745 --- /dev/null +++ b/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs @@ -0,0 +1,15 @@ +using OmniSharp.Models; + +namespace OmniSharp.DotNetTest.Models +{ + public class BaseTestClassRequest : Request + { + public string[] MethodNames { get; set; } + public string TestFrameworkName { get; set; } + + /// + /// e.g. .NETCoreApp, Version=2.0 + /// + public string TargetFrameworkVersion { get; set; } + } +} diff --git a/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs new file mode 100644 index 0000000000..120de61372 --- /dev/null +++ b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs @@ -0,0 +1,10 @@ +using OmniSharp.Mef; +using OmniSharp.Models; + +namespace OmniSharp.DotNetTest.Models +{ + [OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, typeof(DebugTestClassGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse))] + public class DebugTestClassGetStartInfoRequest : BaseTestClassRequest + { + } +} diff --git a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs new file mode 100644 index 0000000000..e4773a557c --- /dev/null +++ b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs @@ -0,0 +1,10 @@ +using OmniSharp.Mef; +using OmniSharp.Models; + +namespace OmniSharp.DotNetTest.Models +{ + [OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse))] + public class RunTestsInClassRequest : BaseTestClassRequest + { + } +} diff --git a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs new file mode 100644 index 0000000000..99c0691dd1 --- /dev/null +++ b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Composition; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.Logging; +using OmniSharp.DotNetTest.Models; +using OmniSharp.Eventing; +using OmniSharp.Mef; +using OmniSharp.Services; + +namespace OmniSharp.DotNetTest.Services +{ + [OmniSharpHandler(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, LanguageNames.CSharp)] + class DebugTestClassService : BaseTestService, + IRequestHandler + { + private DebugSessionManager _debugSessionManager; + + [ImportingConstructor] + public DebugTestClassService(DebugSessionManager debugSessionManager, OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory) + : base(workspace, dotNetCli, eventEmitter, loggerFactory) + { + _debugSessionManager = debugSessionManager; + } + + public async Task Handle(DebugTestClassGetStartInfoRequest request) + { + var testManager = CreateTestManager(request.FileName); + _debugSessionManager.StartSession(testManager); + + return await _debugSessionManager.DebugGetStartInfoAsync(request.MethodNames, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None); + } + } +} diff --git a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs new file mode 100644 index 0000000000..9ab99caebf --- /dev/null +++ b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Composition; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.Logging; +using OmniSharp.DotNetTest.Models; +using OmniSharp.Eventing; +using OmniSharp.Mef; +using OmniSharp.Services; + +namespace OmniSharp.DotNetTest.Services +{ + [OmniSharpHandler(OmniSharpEndpoints.V2.RunAllTestsInClass, LanguageNames.CSharp)] + internal class RunTestsInClassService : BaseTestService + { + [ImportingConstructor] + public RunTestsInClassService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory) + : base(workspace, dotNetCli, eventEmitter, loggerFactory) + { + } + + protected override RunTestResponse HandleRequest(RunTestsInClassRequest request, TestManager testManager) + { + if (testManager.IsConnected) + { + return testManager.RunTest(request.MethodNames, request.TestFrameworkName, request.TargetFrameworkVersion); + } + + var response = new RunTestResponse + { + Failure = "Failed to connect to 'dotnet test' process", + Pass = false + }; + + return response; + } + } +} diff --git a/src/OmniSharp.DotNetTest/TestManager.cs b/src/OmniSharp.DotNetTest/TestManager.cs index 4b6ee42211..de9c7e54c5 100644 --- a/src/OmniSharp.DotNetTest/TestManager.cs +++ b/src/OmniSharp.DotNetTest/TestManager.cs @@ -73,9 +73,21 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE protected abstract void VersionCheck(); public abstract RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion); + + public virtual RunTestResponse RunTest(string[] methodNames, string testFrameworkName, string targetFrameworkVersion) + { + throw new NotImplementedException(); + } + public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string testFrameworkName, string targetFrameworkVersion); public abstract Task DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken); + + public virtual Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + public abstract Task DebugLaunchAsync(CancellationToken cancellationToken); protected virtual bool PrepareToConnect() diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index 2e9167de6f..65c77bc8ae 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -105,7 +105,7 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str { VerifyTestFramework(testFrameworkName); - var testCases = DiscoverTests(methodName, targetFrameworkVersion); + var testCases = DiscoverTests(new string[] { methodName }, targetFrameworkVersion); SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected, new @@ -127,10 +127,13 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str } public override async Task DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) + => await DebugGetStartInfoAsync(new string[] { methodName }, testFrameworkName, targetFrameworkVersion, cancellationToken); + + public override async Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) { VerifyTestFramework(testFrameworkName); - var testCases = await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken); + var testCases = await DiscoverTestsAsync(methodNames, targetFrameworkVersion, cancellationToken); SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected, new @@ -184,10 +187,13 @@ public override async Task DebugLaunchAsync(CancellationToken cancellationToken) } public override RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion) + => RunTest(new string[] { methodName }, testFrameworkName, targetFrameworkVersion); + + public override RunTestResponse RunTest(string[] methodNames, string testFrameworkName, string targetFrameworkVersion) { VerifyTestFramework(testFrameworkName); - var testCases = DiscoverTests(methodName, targetFrameworkVersion); + var testCases = DiscoverTests(methodNames, targetFrameworkVersion); var testResults = new List(); @@ -244,7 +250,7 @@ public override RunTestResponse RunTest(string methodName, string testFrameworkN }; } - private async Task DiscoverTestsAsync(string methodName, string targetFrameworkVersion, CancellationToken cancellationToken) + private async Task DiscoverTestsAsync(string[] methodNames, string targetFrameworkVersion, CancellationToken cancellationToken) { SendMessage(MessageType.StartDiscovery, new @@ -258,6 +264,7 @@ private async Task DiscoverTestsAsync(string methodName, string targ var testCases = new List(); var done = false; + var hashset = new HashSet(methodNames); while (!done) { @@ -286,7 +293,7 @@ private async Task DiscoverTestsAsync(string methodName, string targ testName = testName.Trim(); - if (testName.Equals(methodName, StringComparison.Ordinal)) + if (hashset.Contains(testName, StringComparer.Ordinal)) { testCases.Add(testCase); } @@ -303,9 +310,9 @@ private async Task DiscoverTestsAsync(string methodName, string targ return testCases.ToArray(); } - private TestCase[] DiscoverTests(string methodName, string targetFrameworkVersion) + private TestCase[] DiscoverTests(string[] methodNames, string targetFrameworkVersion) { - return DiscoverTestsAsync(methodName, targetFrameworkVersion, CancellationToken.None).Result; + return DiscoverTestsAsync(methodNames, targetFrameworkVersion, CancellationToken.None).Result; } } }