From 3980673df0fd0529c0eb746cc2903e1ebe87eaea Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 5 Jan 2018 18:38:20 -0800 Subject: [PATCH 01/12] New endpoint for running all tests --- .../OmniSharpEndpoints.cs | 1 + .../Models/RunTestInClassRequest.cs | 17 ++++++++ .../Services/RunTestsInClassService.cs | 41 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs create mode 100644 src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs diff --git a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs index 20314bd619..43f3a9441f 100644 --- a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs +++ b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs @@ -50,6 +50,7 @@ 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"; diff --git a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs new file mode 100644 index 0000000000..af979120d2 --- /dev/null +++ b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs @@ -0,0 +1,17 @@ +using OmniSharp.Mef; +using OmniSharp.Models; + +namespace OmniSharp.DotNetTest.Models +{ + [OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse[]))] + public class RunTestsInClassRequest : Request + { + public string MethodName { get; set; } + public string TestFrameworkName { get; set; } + /// + /// e.g. .NETCoreApp, Version=2.0 + /// + public string TargetFrameworkVersion { get; set; } + public string[] MethodNamesInClass { get; set; } + } +} diff --git a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs new file mode 100644 index 0000000000..483790f9c1 --- /dev/null +++ b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs @@ -0,0 +1,41 @@ +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) + { + List responses = new List(); + if (testManager.IsConnected) + { + foreach (var methodName in request.MethodNamesInClass) + responses.Add(testManager.RunTest(methodName, request.TestFrameworkName, request.TargetFrameworkVersion)); + } + else + { + var response = new RunTestResponse + { + Failure = "Failed to connect to 'dotnet test' process", + Pass = false + }; + responses.Add(response); + } + return responses.ToArray(); + } + } +} From a6876e1c041db158eb71f6e6323f81a5813ad92f Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 8 Jan 2018 15:57:50 -0800 Subject: [PATCH 02/12] Removed method name from run test in class --- src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs index af979120d2..608ac7b21e 100644 --- a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs +++ b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs @@ -6,7 +6,6 @@ namespace OmniSharp.DotNetTest.Models [OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse[]))] public class RunTestsInClassRequest : Request { - public string MethodName { get; set; } public string TestFrameworkName { get; set; } /// /// e.g. .NETCoreApp, Version=2.0 From 61672984bcdb4b05e05d28cc8af33dfa9d4b6914 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 9 Jan 2018 14:35:43 -0800 Subject: [PATCH 03/12] Added code for debug all tests --- .../OmniSharpEndpoints.cs | 2 + .../DebugTestClassGetStartInfoRequest.cs | 16 ++++++++ .../Services/DebugTestClassService.cs | 37 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs create mode 100644 src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs diff --git a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs index 43f3a9441f..db7f63f26d 100644 --- a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs +++ b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs @@ -54,6 +54,8 @@ public static class V2 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/Models/DebugTestClassGetStartInfoRequest.cs b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs new file mode 100644 index 0000000000..e0a611152a --- /dev/null +++ b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs @@ -0,0 +1,16 @@ +using OmniSharp.Mef; +using OmniSharp.Models; + +namespace OmniSharp.DotNetTest.Models +{ + [OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, typeof(DebugTestClassGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse[]))] + class DebugTestClassGetStartInfoRequest : Request + { + public string[] MethodsInClass { get; set; } + public string TestFrameworkName { get; set; } + /// + /// e.g. .NETCoreApp, Version=2.0 + /// + public string TargetFrameworkVersion { get; set; } + } +} diff --git a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs new file mode 100644 index 0000000000..49cb63f4ae --- /dev/null +++ b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs @@ -0,0 +1,37 @@ +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); + + var responses = new List(); + foreach (var methodName in request.MethodsInClass) + responses.Add(await _debugSessionManager.DebugGetStartInfoAsync(methodName, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None)); + return responses.ToArray(); + } + } +} From 2e8dd4583e9058f46ec1e64058f165e8aca447b5 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 10 Jan 2018 14:18:05 -0800 Subject: [PATCH 04/12] Debug All Tests running --- .../DebugSessionManager.cs | 7 +++++ .../DebugTestClassGetStartInfoRequest.cs | 2 +- .../Services/DebugTestClassService.cs | 9 ++---- src/OmniSharp.DotNetTest/TestManager.cs | 5 ++++ src/OmniSharp.DotNetTest/VSTestManager.cs | 28 +++++++++++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/OmniSharp.DotNetTest/DebugSessionManager.cs b/src/OmniSharp.DotNetTest/DebugSessionManager.cs index 1c9354c402..30131212b5 100644 --- a/src/OmniSharp.DotNetTest/DebugSessionManager.cs +++ b/src/OmniSharp.DotNetTest/DebugSessionManager.cs @@ -84,6 +84,13 @@ public Task DebugGetStartInfoAsync(string methodN return _testManager.DebugGetStartInfoAsync(methodName, testFrameworkName, targetFrameworkVersion, cancellationToken); } + public Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) + { + VerifySession(isStarted: true); + + return _testManager.DebugGetStartInfoAsync(methodNames, testFrameworkName, targetFrameworkVersion, cancellationToken); + } + public async Task DebugLaunchAsync(int targetProcessId) { VerifySession(isStarted: true); diff --git a/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs index e0a611152a..dc40517a39 100644 --- a/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs +++ b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs @@ -3,7 +3,7 @@ namespace OmniSharp.DotNetTest.Models { - [OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, typeof(DebugTestClassGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse[]))] + [OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, typeof(DebugTestClassGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse))] class DebugTestClassGetStartInfoRequest : Request { public string[] MethodsInClass { get; set; } diff --git a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs index 49cb63f4ae..2d881aa019 100644 --- a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs @@ -13,7 +13,7 @@ namespace OmniSharp.DotNetTest.Services { [OmniSharpHandler(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, LanguageNames.CSharp)] class DebugTestClassService : BaseTestService, - IRequestHandler + IRequestHandler { private DebugSessionManager _debugSessionManager; @@ -23,15 +23,12 @@ public DebugTestClassService(DebugSessionManager debugSessionManager, OmniSharpW { _debugSessionManager = debugSessionManager; } - public async Task Handle(DebugTestClassGetStartInfoRequest request) + public async Task Handle(DebugTestClassGetStartInfoRequest request) { var testManager = CreateTestManager(request.FileName); _debugSessionManager.StartSession(testManager); - var responses = new List(); - foreach (var methodName in request.MethodsInClass) - responses.Add(await _debugSessionManager.DebugGetStartInfoAsync(methodName, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None)); - return responses.ToArray(); + return await _debugSessionManager.DebugGetStartInfoAsync(request.MethodsInClass, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None); } } } diff --git a/src/OmniSharp.DotNetTest/TestManager.cs b/src/OmniSharp.DotNetTest/TestManager.cs index 4b6ee42211..df774dec52 100644 --- a/src/OmniSharp.DotNetTest/TestManager.cs +++ b/src/OmniSharp.DotNetTest/TestManager.cs @@ -76,6 +76,11 @@ public static TestManager Create(Project project, DotNetCliService dotNetCli, IE 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..46bc226808 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -152,6 +152,34 @@ public override async Task DebugGetStartInfoAsync }; } + public override async Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) + { + VerifyTestFramework(testFrameworkName); + + var testCases = new List(); + foreach(var methodName in methodNames) + testCases.AddRange(await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken)); + + SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected, + new + { + TestCases = testCases, + DebuggingEnabled = true, + RunSettings = GetDefaultRunSettings(targetFrameworkVersion) + }); + + var message = await ReadMessageAsync(cancellationToken); + var startInfo = message.DeserializePayload(); + + return new DebugTestGetStartInfoResponse + { + FileName = startInfo.FileName, + Arguments = startInfo.Arguments, + WorkingDirectory = startInfo.WorkingDirectory, + EnvironmentVariables = startInfo.EnvironmentVariables + }; + } + public override async Task DebugLaunchAsync(CancellationToken cancellationToken) { SendMessage(MessageType.CustomTestHostLaunchCallback, From 2d4d3bb992d4d5a739e254aab0638b00f9f0aaaf Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 12 Jan 2018 16:35:59 -0800 Subject: [PATCH 05/12] Code clean up --- .../OmniSharpEndpoints.cs | 1 - .../DebugSessionManager.cs | 7 ++---- src/OmniSharp.DotNetTest/VSTestManager.cs | 25 +------------------ 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs index db7f63f26d..84f7e8633c 100644 --- a/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs +++ b/src/OmniSharp.Abstractions/OmniSharpEndpoints.cs @@ -55,7 +55,6 @@ public static class V2 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 30131212b5..730d9eb3d6 100644 --- a/src/OmniSharp.DotNetTest/DebugSessionManager.cs +++ b/src/OmniSharp.DotNetTest/DebugSessionManager.cs @@ -78,11 +78,8 @@ public void EndSession() } public Task DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) - { - VerifySession(isStarted: true); - - return _testManager.DebugGetStartInfoAsync(methodName, testFrameworkName, targetFrameworkVersion, cancellationToken); - } + => DebugGetStartInfoAsync(new string[] { methodName }, testFrameworkName, targetFrameworkVersion, cancellationToken); + public Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) { diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index 46bc226808..0d4415607b 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -127,30 +127,7 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str } public override async Task DebugGetStartInfoAsync(string methodName, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) - { - VerifyTestFramework(testFrameworkName); - - var testCases = await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken); - - SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected, - new - { - TestCases = testCases, - DebuggingEnabled = true, - RunSettings = GetDefaultRunSettings(targetFrameworkVersion) - }); - - var message = await ReadMessageAsync(cancellationToken); - var startInfo = message.DeserializePayload(); - - return new DebugTestGetStartInfoResponse - { - FileName = startInfo.FileName, - Arguments = startInfo.Arguments, - WorkingDirectory = startInfo.WorkingDirectory, - EnvironmentVariables = startInfo.EnvironmentVariables - }; - } + => await DebugGetStartInfoAsync(new string[] { methodName}, testFrameworkName, targetFrameworkVersion, cancellationToken); public override async Task DebugGetStartInfoAsync(string[] methodNames, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken) { From 0aa7772fc4ae289a5ea2fea84017e3d6f07c4f99 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 12 Jan 2018 16:43:11 -0800 Subject: [PATCH 06/12] Added newline --- src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs index 483790f9c1..7916364fcb 100644 --- a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs @@ -35,6 +35,7 @@ protected override RunTestResponse[] HandleRequest(RunTestsInClassRequest reques }; responses.Add(response); } + return responses.ToArray(); } } From bf2fc457a376f819c932a75ed44cd689a54d0d92 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 17 Jan 2018 14:17:30 -0800 Subject: [PATCH 07/12] Renamed MethodNames and added Base Class --- src/OmniSharp.DotNetTest/DebugSessionManager.cs | 1 - .../Models/BaseTestClassRequest.cs | 14 ++++++++++++++ .../Models/DebugTestClassGetStartInfoRequest.cs | 8 +------- .../Models/RunTestInClassRequest.cs | 8 +------- .../Services/DebugTestClassService.cs | 2 +- .../Services/RunTestsInClassService.cs | 2 +- src/OmniSharp.DotNetTest/VSTestManager.cs | 6 ++++-- 7 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs diff --git a/src/OmniSharp.DotNetTest/DebugSessionManager.cs b/src/OmniSharp.DotNetTest/DebugSessionManager.cs index 730d9eb3d6..0f4ba7a921 100644 --- a/src/OmniSharp.DotNetTest/DebugSessionManager.cs +++ b/src/OmniSharp.DotNetTest/DebugSessionManager.cs @@ -80,7 +80,6 @@ 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); diff --git a/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs b/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs new file mode 100644 index 0000000000..b551ba40c6 --- /dev/null +++ b/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs @@ -0,0 +1,14 @@ +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 index dc40517a39..120de61372 100644 --- a/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs +++ b/src/OmniSharp.DotNetTest/Models/DebugTestClassGetStartInfoRequest.cs @@ -4,13 +4,7 @@ namespace OmniSharp.DotNetTest.Models { [OmniSharpEndpoint(OmniSharpEndpoints.V2.DebugTestsInClassGetStartInfo, typeof(DebugTestClassGetStartInfoRequest), typeof(DebugTestGetStartInfoResponse))] - class DebugTestClassGetStartInfoRequest : Request + public class DebugTestClassGetStartInfoRequest : BaseTestClassRequest { - public string[] MethodsInClass { 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/RunTestInClassRequest.cs b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs index 608ac7b21e..2b8d1e55e1 100644 --- a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs +++ b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs @@ -4,13 +4,7 @@ namespace OmniSharp.DotNetTest.Models { [OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse[]))] - public class RunTestsInClassRequest : Request + public class RunTestsInClassRequest : BaseTestClassRequest { - public string TestFrameworkName { get; set; } - /// - /// e.g. .NETCoreApp, Version=2.0 - /// - public string TargetFrameworkVersion { get; set; } - public string[] MethodNamesInClass { get; set; } } } diff --git a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs index 2d881aa019..7ea9764e96 100644 --- a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs @@ -28,7 +28,7 @@ public async Task Handle(DebugTestClassGetStartIn var testManager = CreateTestManager(request.FileName); _debugSessionManager.StartSession(testManager); - return await _debugSessionManager.DebugGetStartInfoAsync(request.MethodsInClass, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None); + 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 index 7916364fcb..2be69e96a9 100644 --- a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs @@ -23,7 +23,7 @@ protected override RunTestResponse[] HandleRequest(RunTestsInClassRequest reques List responses = new List(); if (testManager.IsConnected) { - foreach (var methodName in request.MethodNamesInClass) + foreach (var methodName in request.MethodNames) responses.Add(testManager.RunTest(methodName, request.TestFrameworkName, request.TargetFrameworkVersion)); } else diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index 0d4415607b..74399187c5 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -134,8 +134,10 @@ public override async Task DebugGetStartInfoAsync VerifyTestFramework(testFrameworkName); var testCases = new List(); - foreach(var methodName in methodNames) - testCases.AddRange(await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken)); + foreach (var methodName in methodNames) + { + testCases.AddRange(await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken)); + } SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected, new From ddf6978697564ed88c78d378e85cca23aea36c04 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 19 Jan 2018 17:07:39 -0800 Subject: [PATCH 08/12] Changes to return only one run test response --- .../Models/RunTestInClassRequest.cs | 2 +- .../Services/RunTestsInClassService.cs | 24 ++++++++----------- src/OmniSharp.DotNetTest/TestManager.cs | 7 ++++++ src/OmniSharp.DotNetTest/VSTestManager.cs | 11 ++++++++- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs index 2b8d1e55e1..e4773a557c 100644 --- a/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs +++ b/src/OmniSharp.DotNetTest/Models/RunTestInClassRequest.cs @@ -3,7 +3,7 @@ namespace OmniSharp.DotNetTest.Models { - [OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse[]))] + [OmniSharpEndpoint(OmniSharpEndpoints.V2.RunAllTestsInClass, typeof(RunTestsInClassRequest), typeof(RunTestResponse))] public class RunTestsInClassRequest : BaseTestClassRequest { } diff --git a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs index 2be69e96a9..5800052de2 100644 --- a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs @@ -10,7 +10,7 @@ namespace OmniSharp.DotNetTest.Services { [OmniSharpHandler(OmniSharpEndpoints.V2.RunAllTestsInClass, LanguageNames.CSharp)] - internal class RunTestsInClassService : BaseTestService + internal class RunTestsInClassService : BaseTestService { [ImportingConstructor] public RunTestsInClassService(OmniSharpWorkspace workspace, DotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory) @@ -18,25 +18,21 @@ public RunTestsInClassService(OmniSharpWorkspace workspace, DotNetCliService dot { } - protected override RunTestResponse[] HandleRequest(RunTestsInClassRequest request, TestManager testManager) + protected override RunTestResponse HandleRequest(RunTestsInClassRequest request, TestManager testManager) { - List responses = new List(); + if (testManager.IsConnected) { - foreach (var methodName in request.MethodNames) - responses.Add(testManager.RunTest(methodName, request.TestFrameworkName, request.TargetFrameworkVersion)); + return testManager.RunTest(request.MethodNames, request.TestFrameworkName, request.TargetFrameworkVersion); } - else + + var response = new RunTestResponse { - var response = new RunTestResponse - { - Failure = "Failed to connect to 'dotnet test' process", - Pass = false - }; - responses.Add(response); - } + Failure = "Failed to connect to 'dotnet test' process", + Pass = false + }; - return responses.ToArray(); + return response; } } } diff --git a/src/OmniSharp.DotNetTest/TestManager.cs b/src/OmniSharp.DotNetTest/TestManager.cs index df774dec52..de9c7e54c5 100644 --- a/src/OmniSharp.DotNetTest/TestManager.cs +++ b/src/OmniSharp.DotNetTest/TestManager.cs @@ -73,6 +73,12 @@ 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); @@ -81,6 +87,7 @@ public virtual Task DebugGetStartInfoAsync(string { 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 74399187c5..b9480df788 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -191,10 +191,19 @@ 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 testCasesList = new List(); + foreach (var methodName in methodNames) + { + testCasesList.AddRange(DiscoverTests(methodName, targetFrameworkVersion)); + } + + var testCases = testCasesList.ToArray(); var testResults = new List(); From c5b404bd1fdff140ec971a5626afdad3aa78cf09 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 22 Jan 2018 16:16:46 -0800 Subject: [PATCH 09/12] Resolved review comments --- src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs | 1 + src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs | 1 - src/OmniSharp.DotNetTest/VSTestManager.cs | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs index 7ea9764e96..99c0691dd1 100644 --- a/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/DebugTestClassService.cs @@ -23,6 +23,7 @@ public DebugTestClassService(DebugSessionManager debugSessionManager, OmniSharpW { _debugSessionManager = debugSessionManager; } + public async Task Handle(DebugTestClassGetStartInfoRequest request) { var testManager = CreateTestManager(request.FileName); diff --git a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs index 5800052de2..9ab99caebf 100644 --- a/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs +++ b/src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs @@ -20,7 +20,6 @@ public RunTestsInClassService(OmniSharpWorkspace workspace, DotNetCliService dot protected override RunTestResponse HandleRequest(RunTestsInClassRequest request, TestManager testManager) { - if (testManager.IsConnected) { return testManager.RunTest(request.MethodNames, request.TestFrameworkName, request.TargetFrameworkVersion); diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index b9480df788..f23ea61e76 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -191,7 +191,7 @@ public override async Task DebugLaunchAsync(CancellationToken cancellationToken) } public override RunTestResponse RunTest(string methodName, string testFrameworkName, string targetFrameworkVersion) - => RunTest(new string[] { methodName }, testFrameworkName, targetFrameworkVersion); + => RunTest(new string[] { methodName }, testFrameworkName, targetFrameworkVersion); public override RunTestResponse RunTest(string[] methodNames, string testFrameworkName, string targetFrameworkVersion) { From 21f36bcbb54eda9212d09420cb2b6181f0fb1b05 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 23 Jan 2018 12:01:17 -0800 Subject: [PATCH 10/12] Discover tests using an array of strings --- src/OmniSharp.DotNetTest/VSTestManager.cs | 26 +++++++---------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index f23ea61e76..30a2b8bcd1 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,17 +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); + => 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 = new List(); - foreach (var methodName in methodNames) - { - testCases.AddRange(await DiscoverTestsAsync(methodName, targetFrameworkVersion, cancellationToken)); - } + var testCases = await DiscoverTestsAsync(methodNames, targetFrameworkVersion, cancellationToken); SendMessage(MessageType.GetTestRunnerProcessStartInfoForRunSelected, new @@ -197,13 +193,7 @@ public override RunTestResponse RunTest(string[] methodNames, string testFramewo { VerifyTestFramework(testFrameworkName); - var testCasesList = new List(); - foreach (var methodName in methodNames) - { - testCasesList.AddRange(DiscoverTests(methodName, targetFrameworkVersion)); - } - - var testCases = testCasesList.ToArray(); + var testCases = DiscoverTests(methodNames, targetFrameworkVersion); var testResults = new List(); @@ -260,7 +250,7 @@ public override RunTestResponse RunTest(string[] methodNames, string testFramewo }; } - private async Task DiscoverTestsAsync(string methodName, string targetFrameworkVersion, CancellationToken cancellationToken) + private async Task DiscoverTestsAsync(string[] methodNames, string targetFrameworkVersion, CancellationToken cancellationToken) { SendMessage(MessageType.StartDiscovery, new @@ -302,7 +292,7 @@ private async Task DiscoverTestsAsync(string methodName, string targ testName = testName.Trim(); - if (testName.Equals(methodName, StringComparison.Ordinal)) + if (Array.Exists(methodNames, methodName => testName.Equals(methodName, StringComparison.Ordinal))) { testCases.Add(testCase); } @@ -319,9 +309,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; } } } From 9ecc6a2fd29bc317b133652863d93942d3c92ac6 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 23 Jan 2018 14:11:36 -0800 Subject: [PATCH 11/12] Added hashset for faster searching --- src/OmniSharp.DotNetTest/VSTestManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.DotNetTest/VSTestManager.cs b/src/OmniSharp.DotNetTest/VSTestManager.cs index 30a2b8bcd1..65c77bc8ae 100644 --- a/src/OmniSharp.DotNetTest/VSTestManager.cs +++ b/src/OmniSharp.DotNetTest/VSTestManager.cs @@ -264,6 +264,7 @@ private async Task DiscoverTestsAsync(string[] methodNames, string t var testCases = new List(); var done = false; + var hashset = new HashSet(methodNames); while (!done) { @@ -292,7 +293,7 @@ private async Task DiscoverTestsAsync(string[] methodNames, string t testName = testName.Trim(); - if (Array.Exists(methodNames, methodName => testName.Equals(methodName, StringComparison.Ordinal))) + if (hashset.Contains(testName, StringComparer.Ordinal)) { testCases.Add(testCase); } From c67062c8d76c4e5569c67f58b209e4533e813db6 Mon Sep 17 00:00:00 2001 From: akshita31 Date: Wed, 24 Jan 2018 09:43:26 -0800 Subject: [PATCH 12/12] Added new line above doc comment --- src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs b/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs index b551ba40c6..e28fc9a745 100644 --- a/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs +++ b/src/OmniSharp.DotNetTest/Models/BaseTestClassRequest.cs @@ -6,6 +6,7 @@ public class BaseTestClassRequest : Request { public string[] MethodNames { get; set; } public string TestFrameworkName { get; set; } + /// /// e.g. .NETCoreApp, Version=2.0 ///