public async Task<GetTestCommandResponse> GetTestCommand(TestCommandRequest request) { var quickFixes = new List<QuickFix>(); var document = _workspace.GetDocument(request.FileName); var response = new GetTestCommandResponse(); if (document != null) { var semanticModel = await document.GetSemanticModelAsync(); var syntaxTree = semanticModel.SyntaxTree; var sourceText = await document.GetTextAsync(); var position = sourceText.Lines.GetPosition(new LinePosition(request.Line - 1, request.Column - 1)); var node = syntaxTree.GetRoot().FindToken(position).Parent; SyntaxNode method = node.FirstAncestorOrSelf<MethodDeclarationSyntax>(); SyntaxNode type = GetTypeDeclaration(node); if (type == null) { return response; } var symbol = semanticModel.GetDeclaredSymbol(method ?? type); var context = new TestContext(document.Project.FilePath, request.Type, symbol); response.TestCommand = _testCommandProviders .Select(t => t.GetTestCommand(context)) .FirstOrDefault(c => c != null); var directory = Path.GetDirectoryName(document.Project.FilePath); response.Directory = directory; } return response; }
private async Task <string> GetTestCommandArgumentsAsync(string source, TestCommandType testType = TestCommandType.Single) { var workspace = await TestHelpers.CreateSimpleWorkspace(source); var context = new DnxContext(); var projectName = "project.json"; var projectCounter = 1; context.ProjectContextMapping.Add(projectName, projectCounter); context.Projects.Add(projectCounter, new Project { Path = "project.json", Commands = { { "test", "Xunit.KRunner" } } }); ITestCommandProvider testCommandProvider = new DnxTestCommandProvider(context, new FakeEnvironment(), new FakeLoggerFactory(), new NullEventEmitter()); var controller = new TestCommandService(workspace, new [] { testCommandProvider }); var lineColumn = TestHelpers.GetLineAndColumnFromDollar(source); var request = new TestCommandRequest { Line = lineColumn.Line, Column = lineColumn.Column, FileName = "dummy.cs", Buffer = source.Replace("$", ""), Type = testType }; await workspace.BufferManager.UpdateBuffer(request); var testCommand = await controller.Handle(request); return(testCommand.TestCommand); }
private async Task <string> GetTestCommandArgumentsAsync(string source, TestCommandType testType = TestCommandType.Single) { var workspace = TestHelpers.CreateSimpleWorkspace(source); var context = new AspNet5Context(); var projectName = "project.json"; var projectCounter = 1; context.ProjectContextMapping.Add(projectName, projectCounter); context.Projects.Add(projectCounter, new Project { Path = "project.json", Commands = { { "test", "Xunit.KRunner" } } }); var testCommandProviders = new[] { new AspNet5TestCommandProvider(context, new FakeEnvironment(), new FakeLoggerFactory(), new NullEventEmitter(), new FakeOmniSharpOptions()) }; var controller = new TestCommandController(workspace, testCommandProviders); var lineColumn = TestHelpers.GetLineAndColumnFromDollar(source); var request = new TestCommandRequest { Line = lineColumn.Line, Column = lineColumn.Column, FileName = "dummy.cs", Buffer = source.Replace("$", ""), Type = testType }; var bufferFilter = new UpdateBufferFilter(workspace); bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(request, controller)); var testCommand = await controller.GetTestCommand(request); return(testCommand.TestCommand); }
private async Task <string> GetTestCommandAsync(string source, TestCommandType testType) { var testFile = new TestFile("dummy.cs", source); SharedOmniSharpTestHost.AddFilesToWorkspace(testFile); var rh = SharedOmniSharpTestHost.GetRequestHandler <TestCommandService>(OmniSharpEndpoints.TestCommand); OmniSharpConfiguration config = new OmniSharpConfiguration() { MSBuildPath = new BuildPath() { Path = "path\\to\\source" }, TestCommands = new TestCommands() { All = "nunit3-console.exe --noresult --noh {{AssemblyPath}}", Single = "nunit3-console.exe --noresult --noh {{AssemblyPath}} --test={{TypeName}}", Fixture = "nunit3-console.exe --noresult --noh {{AssemblyPath}} --test={{TypeName}}" } }; rh._config = config; var cc = rh._config; rh._testCommandProviders.First().testCommands = TestCommandType.All; var point = testFile.Content.GetPointFromPosition(); var requestHandler = GetRequestHandler(SharedOmniSharpTestHost); var request = new TestCommandRequest { Type = testType, Line = point.Line, FileName = testFile.FileName, Buffer = testFile.Content.Code }; var response = await requestHandler.Handle(request); return(response.TestCommand); }
public static GetContextResponse GetContextInformation(this string editorText) { var cursorPosition = TestHelpers.GetLineAndColumnFromDollar(editorText); editorText = editorText.Replace("$", ""); var solution = new FakeSolution(); var project = new FakeProject(); project.AddFile(editorText); solution.Projects.Add(project); var handler = new GetTestContextHandler(solution, new BufferParser(solution)); var request = new TestCommandRequest { Buffer = editorText, FileName = "myfile", Line = cursorPosition.Line, Column = cursorPosition.Column, }; return(handler.GetContextResponse(request)); }