public async Task Handle_MultipleMixedProvider_SupportsCodeActionResolveFalse()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] {
                new MockCodeActionProvider(),
                new MockCommandProvider(),
                new MockNullCodeActionProvider()
            }, Dispatcher, documentResolver, LanguageServer)
            {
                _supportsCodeActionResolve = false
            };

            var request = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Collection(commandOrCodeActionContainer,
                              c =>
            {
                Assert.True(c.IsCodeAction);
                Assert.True(c.CodeAction is RazorCodeAction);
            },
                              c => Assert.True(c.IsCommand));
        }
示例#2
0
        public async Task Handle_NoProviders()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(
                DocumentMappingService,
                Array.Empty <RazorCodeActionProvider>(),
                Array.Empty <CSharpCodeActionProvider>(),
                Dispatcher,
                documentResolver,
                LanguageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };
            var request = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
                Context      = new ExtendedCodeActionContext()
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Null(commandOrCodeActionContainer);
        }
        public async Task Handle_OneNullReturningProvider()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] {
                new MockNullCodeActionProvider()
            }, Dispatcher, documentResolver, LanguageServer)
            {
                _supportsCodeActionResolve = false
            };

            var request = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Empty(commandOrCodeActionContainer);
        }
示例#4
0
        public async Task Handle_MultipleMixedProvider()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] {
                new MockCodeActionProvider(),
                new NullMockCodeActionProvider(),
                new MockCodeActionProvider(),
                new NullMockCodeActionProvider(),
            }, Dispatcher, documentResolver, LoggerFactory);

            var request = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Equal(2, commandOrCodeActionContainer.Count());
        }
示例#5
0
        public async Task Handle_NoDocument()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeActionEndpoint = new CodeActionEndpoint(new RazorCodeActionProvider[] { }, Dispatcher, EmptyDocumentResolver, LoggerFactory);
            var request            = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Null(commandOrCodeActionContainer);
        }
示例#6
0
        public async Task Handle_MultipleMixedProvider_SupportsCodeActionResolveTrue()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(
                DocumentMappingService,
                new RazorCodeActionProvider[] {
                new MockRazorCodeActionProvider(),
                new MockRazorCommandProvider(),
                new MockNullRazorCodeActionProvider()
            },
                Array.Empty <CSharpCodeActionProvider>(),
                Dispatcher,
                documentResolver,
                LanguageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = true
            };

            var request = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
                Context      = new ExtendedCodeActionContext()
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Collection(commandOrCodeActionContainer,
                              c =>
            {
                Assert.True(c.IsCodeAction);
                Assert.True(c.CodeAction is CodeAction);
            },
                              c =>
            {
                Assert.True(c.IsCodeAction);
                Assert.True(c.CodeAction is CodeAction);
            });
        }
        public async Task Handle_NoDocument()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeActionEndpoint = new CodeActionEndpoint(Array.Empty <RazorCodeActionProvider>(), Dispatcher, EmptyDocumentResolver, LanguageServer)
            {
                _supportsCodeActionResolve = false
            };
            var request = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Null(commandOrCodeActionContainer);
        }
示例#8
0
        public async Task GetCSharpCodeActionsFromLanguageServerAsync_InvalidRangeMapping()
        {
            // Arrange
            var   documentPath           = "C:/path/to/Page.razor";
            var   codeDocument           = CreateCodeDocument("@code {}");
            var   documentResolver       = CreateDocumentResolver(documentPath, codeDocument);
            Range projectedRange         = null;
            var   documentMappingService = Mock.Of <DefaultRazorDocumentMappingService>(
                d => d.TryMapToProjectedDocumentRange(It.IsAny <RazorCodeDocument>(), It.IsAny <Range>(), out projectedRange) == false
                );
            var codeActionEndpoint = new CodeActionEndpoint(
                documentMappingService,
                Array.Empty <RazorCodeActionProvider>(),
                new CSharpCodeActionProvider[] {
                new MockCSharpCodeActionProvider()
            },
                Dispatcher,
                documentResolver,
                LanguageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var initialRange = new Range(new Position(0, 1), new Position(0, 1));
            var request      = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = initialRange,
                Context      = new ExtendedCodeActionContext()
            };

            var context = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, default);

            // Act
            var results = await codeActionEndpoint.GetCSharpCodeActionsFromLanguageServerAsync(context, default);

            // Assert
            Assert.Empty(results);
            Assert.Equal(initialRange, context.Request.Range);
        }
示例#9
0
        public async Task Handle_MultipleMixedProvider()
        {
            // Arrange
            var documentPath           = "C:/path/to/Page.razor";
            var codeDocument           = CreateCodeDocument("@code {}");
            var documentResolver       = CreateDocumentResolver(documentPath, codeDocument);
            var documentMappingService = CreateDocumentMappingService();
            var languageServer         = CreateLanguageServer();
            var codeActionEndpoint     = new CodeActionEndpoint(
                documentMappingService,
                new RazorCodeActionProvider[] {
                new MockRazorCodeActionProvider(),
                new MockNullRazorCodeActionProvider(),
                new MockRazorCodeActionProvider(),
                new MockNullRazorCodeActionProvider(),
            },
                new CSharpCodeActionProvider[] {
                new MockCSharpCodeActionProvider(),
                new MockCSharpCodeActionProvider()
            },
                Dispatcher,
                documentResolver,
                languageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var request = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(new Position(0, 1), new Position(0, 1)),
                Context      = new ExtendedCodeActionContext()
            };

            // Act
            var commandOrCodeActionContainer = await codeActionEndpoint.Handle(request, default);

            // Assert
            Assert.Equal(4, commandOrCodeActionContainer.Count());
        }
示例#10
0
        public async Task GetCSharpCodeActionsFromLanguageServerAsync_ReturnsCodeActions()
        {
            // Arrange
            var documentPath           = "C:/path/to/Page.razor";
            var codeDocument           = CreateCodeDocument("@code {}");
            var documentResolver       = CreateDocumentResolver(documentPath, codeDocument);
            var projectedRange         = new Range(new Position(15, 2), new Position(15, 2));
            var documentMappingService = CreateDocumentMappingService(projectedRange);
            var languageServer         = CreateLanguageServer();
            var codeActionEndpoint     = new CodeActionEndpoint(
                documentMappingService,
                Array.Empty <RazorCodeActionProvider>(),
                new CSharpCodeActionProvider[] {
                new MockCSharpCodeActionProvider()
            },
                Dispatcher,
                documentResolver,
                languageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var initialRange = new Range(new Position(0, 1), new Position(0, 1));
            var request      = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = initialRange,
                Context      = new ExtendedCodeActionContext()
            };

            var context = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, default);

            // Act
            var results = await codeActionEndpoint.GetCSharpCodeActionsFromLanguageServerAsync(context, default);

            // Assert
            Assert.Single(results);
            Assert.Equal(projectedRange, context.Request.Range);
        }
示例#11
0
        public async Task GenerateRazorCodeActionContextAsync_WithSelectionRange()
        {
            // Arrange
            var documentPath       = "C:/path/to/Page.razor";
            var codeDocument       = CreateCodeDocument("@code {}");
            var documentResolver   = CreateDocumentResolver(documentPath, codeDocument);
            var codeActionEndpoint = new CodeActionEndpoint(
                DocumentMappingService,
                new RazorCodeActionProvider[] {
                new MockRazorCodeActionProvider()
            },
                Array.Empty <CSharpCodeActionProvider>(),
                Dispatcher,
                documentResolver,
                LanguageServer,
                LanguageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

            var initialRange   = new Range(new Position(0, 1), new Position(0, 1));
            var selectionRange = new Range(new Position(0, 5), new Position(0, 5));
            var request        = new RazorCodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = initialRange,
                Context      = new ExtendedCodeActionContext()
                {
                    SelectionRange = selectionRange,
                }
            };

            // Act
            var razorCodeActionContext = await codeActionEndpoint.GenerateRazorCodeActionContextAsync(request, default);

            // Assert
            Assert.NotNull(razorCodeActionContext);
            Assert.Equal(selectionRange, razorCodeActionContext.Request.Range);
        }