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);
        }
Пример #2
0
        public async Task Handle_OneCodeActionProviderWithMultipleCodeActions()
        {
            // 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 MockMultipleRazorCodeActionProvider(),
            },
                Array.Empty <CSharpCodeActionProvider>(),
                LegacyDispatcher,
                documentResolver,
                _languageServer,
                _languageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

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

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

            // Assert
            Assert.Equal(2, commandOrCodeActionContainer.Count());
        }
        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 RazorCodeAction);
            },
                              c =>
            {
                Assert.True(c.IsCodeAction);
                Assert.True(c.CodeAction is RazorCodeAction);
            });
        }
Пример #4
0
        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(
                _documentMappingService,
                new RazorCodeActionProvider[] {
                new MockRazorCodeActionProvider(),
                new MockRazorCommandProvider(),
                new MockNullRazorCodeActionProvider()
            },
                Array.Empty <CSharpCodeActionProvider>(),
                LegacyDispatcher,
                documentResolver,
                _languageServer,
                _languageServerFeatureOptions)
            {
                _supportsCodeActionResolve = false
            };

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

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

            // Assert
            Assert.Collection(commandOrCodeActionContainer,
                              c =>
            {
                Assert.True(c.IsCommand);
                var command          = Assert.IsType <Command>(c.Command);
                var codeActionParams = command.Arguments.First().ToObject <RazorCodeActionResolutionParams>();
                Assert.Equal(LanguageServerConstants.CodeActions.EditBasedCodeActionCommand, codeActionParams.Action);
            },
                              c => Assert.True(c.IsCommand));
        }
        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());
        }