public async Task ResolveCodeActionsAsync_ReturnsSingleCodeAction()
        {
            // Arrange
            var requestInvoker        = new Mock <LSPRequestInvoker>(MockBehavior.Strict);
            var csharpVirtualDocument = new CSharpVirtualDocumentSnapshot(new Uri("C:/path/to/file.razor.g.cs"), TextBuffer.CurrentSnapshot, hostDocumentSyncVersion: 0);
            var documentManager       = new TestDocumentManager();
            var razorUri = new Uri("C:/path/to/file.razor");

            documentManager.AddDocument(razorUri, new TestLSPDocumentSnapshot(razorUri, version: 0, "Some Content", csharpVirtualDocument));
            var expectedCodeAction = new VSInternalCodeAction()
            {
                Title = "Something",
                Data  = new object()
            };
            var unexpectedCodeAction = new VSInternalCodeAction()
            {
                Title = "Something Else",
                Data  = new object()
            };

            async IAsyncEnumerable <ReinvocationResponse <VSInternalCodeAction> > GetExpectedResultsAsync()
            {
                yield return(new ReinvocationResponse <VSInternalCodeAction>("languageClient", expectedCodeAction));

                yield return(new ReinvocationResponse <VSInternalCodeAction>("languageClient", unexpectedCodeAction));

                await Task.CompletedTask;
            }

            var expectedResponses = GetExpectedResultsAsync();

            requestInvoker.Setup(invoker => invoker.ReinvokeRequestOnMultipleServersAsync <VSInternalCodeAction, VSInternalCodeAction>(
                                     It.IsAny <ITextBuffer>(),
                                     Methods.CodeActionResolveName,
                                     It.IsAny <Func <JToken, bool> >(),
                                     It.IsAny <VSInternalCodeAction>(),
                                     It.IsAny <CancellationToken>()
                                     )).Returns(expectedResponses);

            var uIContextManager     = new Mock <RazorUIContextManager>(MockBehavior.Strict);
            var disposable           = new Mock <IDisposable>(MockBehavior.Strict);
            var clientOptionsMonitor = new Mock <RazorLSPClientOptionsMonitor>(MockBehavior.Strict);
            var documentSynchronizer = new Mock <LSPDocumentSynchronizer>(MockBehavior.Strict);

            var target = new DefaultRazorLanguageServerCustomMessageTarget(
                documentManager, JoinableTaskContext, requestInvoker.Object,
                uIContextManager.Object, disposable.Object, clientOptionsMonitor.Object, documentSynchronizer.Object);
            var codeAction = new VSInternalCodeAction()
            {
                Title = "Something",
            };
            var request = new RazorResolveCodeActionParams(razorUri, codeAction);

            // Act
            var result = await target.ResolveCodeActionsAsync(request, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.Equal(expectedCodeAction.Title, result.Title);
        }
Exemple #2
0
        private static async Task <LSP.VSInternalCodeAction> RunGetCodeActionResolveAsync(
            TestLspServer testLspServer,
            VSInternalCodeAction unresolvedCodeAction)
        {
            var result = (VSInternalCodeAction)await testLspServer.ExecuteRequestAsync <LSP.CodeAction, LSP.CodeAction>(
                LSP.Methods.CodeActionResolveName, unresolvedCodeAction, CancellationToken.None);

            return(result);
        }