Beispiel #1
0
        public async Task ProvideAsync_FunctionsBlock_ValidCodeActions_ReturnsEmpty()
        {
            // Arrange
            var documentPath = "c:/Test.razor";
            var contents     = "@functions { Path; }";
            var request      = new CodeActionParams()
            {
                TextDocument = new TextDocumentIdentifier(new Uri(documentPath)),
                Range        = new Range(),
                Context      = new CodeActionContext()
            };

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

            context.CodeDocument.SetFileKind(FileKinds.Legacy);

            var provider = new DefaultCSharpCodeActionProvider();

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

            // Assert
            Assert.Empty(providedCodeActions);
        }
Beispiel #2
0
        public async Task ProvideAsync_ValidCodeActions_ReturnsProvidedCodeAction()
        {
            // 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();

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

            // Assert
            Assert.Equal(SupportedCodeActions.Length, providedCodeActions.Count);
            var providedNames = providedCodeActions.Select(action => action.Name);
            var expectedNames = SupportedCodeActions.Select(action => action.Name);

            Assert.Equal(expectedNames, providedNames);
        }
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 RazorCodeAction[]
            {
                new RazorCodeAction()
                {
                    Title = "Do something not really supported in razor",
                    Name  = "Non-existant name"
                }
            };

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

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

            var codeActions = new RazorCodeAction[]
            {
                new RazorCodeAction()
                {
                    Title = "Do something not really supported in razor"
                },
                new RazorCodeAction()
                {
                    // 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);
        }
        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);
            }
        }