protected async Task AssertNavigatedAsync(string code, bool next, SourceCodeKind?sourceCodeKind = null)
        {
            var kinds = sourceCodeKind != null
                ? SpecializedCollections.SingletonEnumerable(sourceCodeKind.Value)
                : new[] { SourceCodeKind.Regular, SourceCodeKind.Script };

            foreach (var kind in kinds)
            {
                using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                           LanguageName,
                           compilationOptions: null,
                           parseOptions: DefaultParseOptions.WithKind(kind),
                           content: code))
                {
                    var hostDocument = workspace.DocumentWithCursor;
                    var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                    Assert.Empty((await document.GetSyntaxTreeAsync()).GetDiagnostics());
                    var targetPosition = await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
                        document,
                        hostDocument.CursorPosition.Value,
                        next,
                        CancellationToken.None);

                    Assert.NotNull(targetPosition);
                    Assert.Equal(hostDocument.SelectedSpans.Single().Start, targetPosition.Value);
                }
            }
        }
        private async Task InsertText(string code, string text, bool expectDocumentAnalysis, string language = LanguageNames.CSharp)
        {
            using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                       SolutionCrawler, language, compilationOptions: null, parseOptions: null, content: new string[] { code }))
            {
                var analyzer   = new Analyzer();
                var lazyWorker = new Lazy <IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>(() => new AnalyzerProvider(analyzer), Metadata.Crawler);
                var service    = new SolutionCrawlerRegistrationService(new[] { lazyWorker }, GetListeners(workspace.ExportProvider));

                service.Register(workspace);

                var testDocument = workspace.Documents.First();

                var insertPosition = testDocument.CursorPosition;
                var textBuffer     = testDocument.GetTextBuffer();

                using (var edit = textBuffer.CreateEdit())
                {
                    edit.Insert(insertPosition.Value, text);
                    edit.Apply();
                }

                await WaitAsync(service, workspace);

                service.Unregister(workspace);

                Assert.Equal(1, analyzer.SyntaxDocumentIds.Count);
                Assert.Equal(expectDocumentAnalysis ? 1 : 0, analyzer.DocumentIds.Count);
            }
        }
Example #3
0
        protected async Task VerifyNoRegionsAsync(string markupCode)
        {
            using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: new[] { markupCode }))
            {
                var hostDocument = workspace.Documents.Single();
                Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position.");
                var position = hostDocument.CursorPosition.Value;

                var document      = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                var actualRegions = await GetRegionsAsync(document, position);

                Assert.True(actualRegions.Length == 0, $"Expected no regions but found {actualRegions.Length}.");
            }
        }
 private static async Task <int?> GetTargetPositionAsync(string code, bool next)
 {
     using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                LanguageNames.CSharp,
                new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
                CSharpParseOptions.Default,
                code))
     {
         var hostDocument = workspace.DocumentWithCursor;
         var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
         Assert.Empty((await document.GetSyntaxTreeAsync()).GetDiagnostics());
         return(await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
                    document,
                    hostDocument.CursorPosition.Value,
                    next,
                    CancellationToken.None));
     }
 }
        protected async Task <int?> GetTargetPositionAsync(string code, bool next)
        {
            using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                       LanguageName,
                       compilationOptions: null,
                       parseOptions: DefaultParseOptions,
                       content: code))
            {
                var hostDocument = workspace.DocumentWithCursor;
                var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                Assert.Empty((await document.GetSyntaxTreeAsync()).GetDiagnostics());

                return(await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
                           document,
                           hostDocument.CursorPosition.Value,
                           next,
                           CancellationToken.None));
            }
        }
Example #6
0
        protected async Task VerifyRegionsAsync(string markupCode, params Tuple <string, string, string, bool, bool>[] expectedRegionData)
        {
            using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(WorkspaceKind, LanguageName, compilationOptions: null, parseOptions: null, content: new[] { markupCode }))
            {
                var hostDocument = workspace.Documents.Single();
                Assert.True(hostDocument.CursorPosition.HasValue, "Test must specify a position.");
                var position = hostDocument.CursorPosition.Value;

                var expectedRegions = expectedRegionData.Select(data => CreateOutliningSpan(data, hostDocument.AnnotatedSpans)).ToArray();

                var document      = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                var actualRegions = await GetRegionsAsync(document, position);

                Assert.True(expectedRegions.Length == actualRegions.Length, $"Expected {expectedRegions.Length} regions but there were {actualRegions.Length}");

                for (int i = 0; i < expectedRegions.Length; i++)
                {
                    AssertRegion(expectedRegions[i], actualRegions[i]);
                }
            }
        }