public async Task ProvideAsync_SupportsCodeActionResolveFalse_ValidCodeActions_ReturnsEmpty()
        {
            // Arrange
            var provider = new DefaultCSharpCodeActionProvider();
            var context  = CreateCodeActionContext(supportsCodeActionResolve: false);

            // Act
            var providedCodeActions = await provider.ProvideAsync(context, SupportedCodeActions, default);

            // Assert
            Assert.Empty(providedCodeActions);
        }
        public async Task ProvideAsync_ValidCodeActions_ReturnsProvidedCodeAction()
        {
            // Arrange
            var provider = new DefaultCSharpCodeActionProvider();
            var context  = CreateCodeActionContext(supportsCodeActionResolve: true);

            // Act
            var providedCodeActions = await provider.ProvideAsync(context, SupportedCodeActions, default);

            // Assert
            Assert.Equal(SupportedCodeActions.Length, providedCodeActions.Count);

            for (var i = 0; i < SupportedCodeActions.Length; i++)
            {
                Assert.Equal(SupportedCodeActions[i].Title, providedCodeActions.ElementAt(i).Title);
            }
        }
Beispiel #3
0
        public async Task ProvideAsync_InvalidCodeActions_ReturnsNoCodeActions()
        {
            // Arrange
            var documentPath = "c:/Test.razor";
            var contents     = "@code { Path; }";
            var request      = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(),
                Context      = new CodeActionContext()
            };

            var location = new SourceLocation(8, -1, -1);
            var context  = CreateRazorCodeActionContext(request, location, documentPath, contents, new SourceSpan(8, 4));

            context.CodeDocument.SetFileKind(FileKinds.Legacy);

            var provider = new DefaultCSharpCodeActionProvider();

            var codeActions = new CodeAction[]
            {
                new CodeAction()
                {
                    Title = "Do something not really supported in razor"
                },
                new CodeAction()
                {
                    // Invalid regex pattern shouldn't match
                    Title = "Generate constructor 'Counter(int)' xyz"
                }
            };

            // Act
            var providedCodeActions = await provider.ProvideAsync(context, codeActions, default);

            // Assert
            Assert.Empty(providedCodeActions);
        }