Example #1
0
        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);
        }
        private async Task <RenameResponse> SendRequest(OmnisharpWorkspace workspace,
                                                        string renameTo,
                                                        string filename,
                                                        string fileContent,
                                                        bool wantsTextChanges = false,
                                                        bool applyTextChanges = true)
        {
            var lineColumn = TestHelpers.GetLineAndColumnFromDollar(fileContent);
            var controller = new OmnisharpController(workspace, new FakeOmniSharpOptions());
            var request    = new RenameRequest
            {
                Line             = lineColumn.Line,
                Column           = lineColumn.Column,
                RenameTo         = renameTo,
                FileName         = filename,
                Buffer           = fileContent.Replace("$", ""),
                WantsTextChanges = wantsTextChanges,
                ApplyTextChanges = applyTextChanges
            };

            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(request, controller));

            return(await controller.Rename(request));
        }
        public async Task UpdateBuffer_AddsNewDocumentsIfNeeded()
        {
            var workspace = TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "test.cs", "class C {}" }
            });

            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                FileName = "test2.cs", Buffer = "interface I {}"
            }));

            Assert.Equal(2, workspace.CurrentSolution.GetDocumentIdsWithFilePath("test2.cs").Length);
            var docId = workspace.CurrentSolution.GetDocumentIdsWithFilePath("test2.cs").FirstOrDefault();

            Assert.NotNull(docId);
            var sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("interface I {}", sourceText.ToString());

            docId = workspace.CurrentSolution.GetDocumentIdsWithFilePath("test.cs").FirstOrDefault();
            Assert.NotNull(docId);
            sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("class C {}", sourceText.ToString());
        }
        private async Task <QuickFixResponse> FindRegions(string source)
        {
            var workspace    = TestHelpers.CreateSimpleWorkspace(source);
            var controller   = new OmnisharpController(workspace, new FakeOmniSharpOptions());
            var request      = CreateRequest(source);
            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(request, controller));
            return(await controller.GoToRegion(request));
        }
        private async Task <QuickFixResponse> FindUsages(Dictionary <string, string> sources, string currentFile, bool onlyThisFile, bool excludeDefinition = false)
        {
            var workspace  = TestHelpers.CreateSimpleWorkspace(sources);
            var controller = new OmnisharpController(workspace, null);
            var request    = CreateRequest(sources[currentFile], currentFile, excludeDefinition);

            request.OnlyThisFile = onlyThisFile;
            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(request, controller));
            return(await controller.FindUsages(request));
        }
Example #6
0
        private async Task <IEnumerable <ISymbol> > FindImplementations(string source)
        {
            var workspace    = TestHelpers.CreateSimpleWorkspace(source);
            var controller   = new OmnisharpController(workspace, new FakeOmniSharpOptions());
            var request      = CreateRequest(source);
            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(request, controller));
            var implementations = await controller.FindImplementations(request);

            return(await TestHelpers.SymbolsFromQuickFixes(workspace, implementations.QuickFixes));
        }
        public async Task UpdateBuffer_HandlesVoidRequest()
        {
            var workspace = TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "test.cs", "class C {}" }
            });

            var bufferFilter = new UpdateBufferFilter(workspace);
            var docId        = workspace.CurrentSolution.GetDocumentIdsWithFilePath("test.cs").First();

            // ignore void buffers
            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
            }));
            var sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("class C {}", sourceText.ToString());

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                FileName = "test.cs"
            }));
            sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("class C {}", sourceText.ToString());

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                Buffer = "// c", FileName = "some_other_file.cs"
            }));
            sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("class C {}", sourceText.ToString());

            // valid updates
            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                FileName = "test.cs", Buffer = "interface I {}"
            }));
            sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("interface I {}", sourceText.ToString());

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                FileName = "test.cs", Buffer = ""
            }));
            sourceText = await workspace.CurrentSolution.GetDocument(docId).GetTextAsync();

            Assert.Equal("", sourceText.ToString());
        }
Example #8
0
        private async Task <GetTestCommandResponse> GetTestCommandAsync(string source)
        {
            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) };
            var controller           = new TestCommandController(workspace, testCommandProviders);
            var request      = CreateRequest(source);
            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(request, controller));
            return(await controller.GetTestCommand(request));
        }
        public async Task UpdateBuffer_TransientDocumentsDisappearWhenProjectAddsThem()
        {
            var workspace = TestHelpers.CreateSimpleWorkspace(new Dictionary <string, string>
            {
                { "test.cs", "class C {}" }
            });
            var bufferFilter = new UpdateBufferFilter(workspace);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                FileName = "transient.cs", Buffer = "interface I {}"
            }));

            var docIds = workspace.CurrentSolution.GetDocumentIdsWithFilePath("transient.cs");

            Assert.Equal(2, docIds.Length);

            // simulate a project system adding the file for real
            var project1 = workspace.CurrentSolution.Projects.First();
            var document = DocumentInfo.Create(DocumentId.CreateNewId(project1.Id), "transient.cs",
                                               loader: TextLoader.From(TextAndVersion.Create(SourceText.From("enum E{}"), VersionStamp.Create())),
                                               filePath: "transient.cs");

            workspace.CurrentSolution.AddDocument(document);

            docIds = workspace.CurrentSolution.GetDocumentIdsWithFilePath("transient.cs");
            Assert.Equal(2, docIds.Length);

            bufferFilter.OnActionExecuting(TestHelpers.CreateActionExecutingContext(new Models.Request()
            {
                FileName = "transient.cs", Buffer = "enum E {}"
            }));
            var sourceText = await workspace.CurrentSolution.GetDocument(docIds.First()).GetTextAsync();

            Assert.Equal("enum E {}", sourceText.ToString());
            sourceText = await workspace.CurrentSolution.GetDocument(docIds.Last()).GetTextAsync();

            Assert.Equal("enum E {}", sourceText.ToString());
        }