Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RunTestsInContext #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pipelines/init.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
# Configuration: Release
Verbosity: Normal
DotNetVersion: "3.0.100"
DotNetVersion: "3.1.201"
CakeVersion: "0.32.1"
NuGetVersion: "4.9.2"
steps:
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:

variables:
Verbosity: Diagnostic
DotNetVersion: "3.0.100"
DotNetVersion: "3.1.201"
CakeVersion: "0.32.1"
NuGetVersion: "4.9.2"
GitVersionVersion: "5.0.1"
Expand Down
2 changes: 1 addition & 1 deletion build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"DotNetInstallScriptURL": "https://dot.net/v1",
"DotNetChannel": "Preview",
"DotNetVersions": [
"3.0.100",
"3.1.201",
"5.0.100-preview.2.20169.1"
],
"RequiredMonoVersion": "6.6.0",
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.0.100"
"version": "3.1.201"
}
}
1 change: 1 addition & 0 deletions src/OmniSharp.Abstractions/OmniSharpEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ 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";
public const string RunTestsInContext = "/v2/runtestsincontext";

public const string BlockStructure = "/v2/blockstructure";
public const string CodeStructure = "/v2/codestructure";
Expand Down
18 changes: 18 additions & 0 deletions src/OmniSharp.DotNetTest/Models/RunTestsInContextRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#nullable enable

using OmniSharp.Mef;
using OmniSharp.Models;

namespace OmniSharp.DotNetTest.Models
{
[OmniSharpEndpoint(OmniSharpEndpoints.V2.RunTestsInContext, typeof(RunTestsInContextRequest), typeof(RunTestResponse))]
public class RunTestsInContextRequest : Request
{
public string? RunSettings { get; set; }
public string TestFrameworkName { get; set; } = null!;
/// <summary>
/// e.g. .NETCoreApp, Version=2.0
/// </summary>
public string? TargetFrameworkVersion { get; set; }
}
}
11 changes: 4 additions & 7 deletions src/OmniSharp.DotNetTest/Services/BaseTestService`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ protected BaseTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNet
{
}

protected abstract TResponse HandleRequest(TRequest request, TestManager testManager);
protected abstract Task<TResponse> HandleRequest(TRequest request, TestManager testManager);

public Task<TResponse> Handle(TRequest request)
public async Task<TResponse> Handle(TRequest request)
{
using (var testManager = CreateTestManager(request.FileName))
{
var response = HandleRequest(request, testManager);
return Task.FromResult(response);
}
using var testManager = CreateTestManager(request.FileName);
return await HandleRequest(request, testManager);
}
}
}
5 changes: 3 additions & 2 deletions src/OmniSharp.DotNetTest/Services/GetTestStartInfoService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -17,9 +18,9 @@ public GetTestStartInfoService(OmniSharpWorkspace workspace, IDotNetCliService d
{
}

protected override GetTestStartInfoResponse HandleRequest(GetTestStartInfoRequest request, TestManager testManager)
protected override Task<GetTestStartInfoResponse> HandleRequest(GetTestStartInfoRequest request, TestManager testManager)
{
return testManager.GetTestStartInfo(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion);
return testManager.GetTestStartInfoAsync(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, cancellationToken: default);
}
}
}
8 changes: 5 additions & 3 deletions src/OmniSharp.DotNetTest/Services/RunTestService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -17,11 +19,11 @@ public RunTestService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli,
{
}

protected override RunTestResponse HandleRequest(RunTestRequest request, TestManager testManager)
protected override Task<RunTestResponse> HandleRequest(RunTestRequest request, TestManager testManager)
{
if (testManager.IsConnected)
{
return testManager.RunTest(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion);
return testManager.RunTestAsync(request.MethodName, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None);
}

var response = new RunTestResponse
Expand All @@ -30,7 +32,7 @@ protected override RunTestResponse HandleRequest(RunTestRequest request, TestMan
Pass = false
};

return response;
return Task.FromResult(response);
}
}
}
6 changes: 4 additions & 2 deletions src/OmniSharp.DotNetTest/Services/RunTestsInClassService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using OmniSharp.DotNetTest.Models;
Expand All @@ -17,11 +19,11 @@ public RunTestsInClassService(OmniSharpWorkspace workspace, IDotNetCliService do
{
}

protected override RunTestResponse HandleRequest(RunTestsInClassRequest request, TestManager testManager)
protected override async Task<RunTestResponse> HandleRequest(RunTestsInClassRequest request, TestManager testManager)
{
if (testManager.IsConnected)
{
return testManager.RunTest(request.MethodNames, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion);
return await testManager.RunTestAsync(request.MethodNames, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None);
}

var response = new RunTestResponse
Expand Down
43 changes: 43 additions & 0 deletions src/OmniSharp.DotNetTest/Services/RunTestsInContextService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#nullable enable

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.RunTestsInContext, LanguageNames.CSharp)]
internal class RunTestsInContextService : BaseTestService, IRequestHandler<RunTestsInContextRequest, RunTestResponse>
{
[ImportingConstructor]
public RunTestsInContextService(OmniSharpWorkspace workspace, IDotNetCliService dotNetCli, IEventEmitter eventEmitter, ILoggerFactory loggerFactory)
: base(workspace, dotNetCli, eventEmitter, loggerFactory)
{
}

public async Task<RunTestResponse> Handle(RunTestsInContextRequest request)
{
var document = Workspace.GetDocument(request.FileName);
using var testManager = TestManager.Start(document.Project, DotNetCli, EventEmitter, LoggerFactory);

if (testManager.IsConnected)
{
return await testManager.RunTestsInContextAsync(request.Line, request.Column, document, request.RunSettings, request.TestFrameworkName, request.TargetFrameworkVersion, CancellationToken.None);
}

var response = new RunTestResponse
{
Failure = "Failed to connect to 'dotnet test' process",
Pass = false
};

return response;
}
}
}
27 changes: 15 additions & 12 deletions src/OmniSharp.DotNetTest/TestFrameworks/TestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@ namespace OmniSharp.DotNetTest.TestFrameworks
{
internal abstract class TestFramework
{
private static readonly ImmutableDictionary<string, TestFramework> s_frameworks;
private static readonly ImmutableArray<TestFramework> s_frameworks;

static TestFramework()
{
var builder = ImmutableDictionary.CreateBuilder<string, TestFramework>();
var builder = ImmutableArray.CreateBuilder<TestFramework>();

var nunit = new NUnitTestFramework();
var xunit = new XunitTestFramework();
var mstest = new MSTestFramework();

builder.Add(nunit.Name, nunit);
builder.Add(xunit.Name, xunit);
builder.Add(mstest.Name, mstest);
builder.Add(nunit);
builder.Add(xunit);
builder.Add(mstest);

s_frameworks = builder.ToImmutable();
}

public static TestFramework GetFramework(string name)
{
return s_frameworks.TryGetValue(name, out var result)
? result
: null;
foreach (var framework in s_frameworks)
{
if (framework.Name == name)
{
return framework;
}
}

return null;
}

public static IEnumerable<TestFramework> GetFrameworks()
{
foreach (var kvp in s_frameworks)
{
yield return kvp.Value;
}
return s_frameworks;
}

public abstract string FeatureName { get; }
Expand Down
15 changes: 8 additions & 7 deletions src/OmniSharp.DotNetTest/TestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,22 @@ public static TestManager Create(Project project, IDotNetCliService dotNetCli, I
{
throw new NotSupportedException("Legacy .NET SDK is not supported");
}

return (TestManager)new VSTestManager(project, workingDirectory, dotNetCli, version, eventEmitter, loggerFactory);
}

protected abstract string GetCliTestArguments(int port, int parentProcessId);
protected abstract void VersionCheck();

public abstract RunTestResponse RunTest(string methodName, string runSettings, string testFrameworkName, string targetFrameworkVersion);
#nullable enable
public abstract Task<RunTestResponse> RunTestsInContextAsync(int lineNumber, int column, Document contextDocument, string? runSettings, string testFrameWorkName, string? targetFrameworkVersion, CancellationToken cancellationToken);
#nullable restore

public virtual RunTestResponse RunTest(string[] methodNames, string runSettings, string testFrameworkName, string targetFrameworkVersion)
{
throw new NotImplementedException();
}
public abstract Task<RunTestResponse> RunTestAsync(string methodName, string runSettings, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken);

public abstract Task<RunTestResponse> RunTestAsync(string[] methodNames, string runSettings, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken);

public abstract GetTestStartInfoResponse GetTestStartInfo(string methodName, string runSettings, string testFrameworkName, string targetFrameworkVersion);
public abstract Task<GetTestStartInfoResponse> GetTestStartInfoAsync(string methodName, string runSettings, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken);

public abstract Task<DebugTestGetStartInfoResponse> DebugGetStartInfoAsync(string methodName, string runSettings, string testFrameworkName, string targetFrameworkVersion, CancellationToken cancellationToken);

Expand Down
Loading