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 = 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" } } }); var testCommandProviders = new[] { new DnxTestCommandProvider(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; }