Beispiel #1
0
        public async Task TryGetProvisionalCompletionsAsync_AtCorrectProvisionalCompletionPoint_ReturnsExpectedResult()
        {
            // Arrange
            var completionRequest = new CompletionParams()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = Uri
                },
                Context = new CompletionContext()
                {
                    TriggerKind      = CompletionTriggerKind.TriggerCharacter,
                    TriggerCharacter = "."
                },
                Position = new Position(0, 1)
            };

            var virtualDocumentUri = new Uri("C:/path/to/file.razor__virtual.cs");

            var documentManager = new TestDocumentManager();

            var languageServerCalled = false;
            var expectedItem         = new CompletionItem()
            {
                InsertText = "DateTime"
            };
            var requestInvoker = new Mock <LSPRequestInvoker>(MockBehavior.Strict);

            requestInvoker
            .Setup(r => r.ReinvokeRequestOnServerAsync <CompletionParams, SumType <CompletionItem[], CompletionList>?>(It.IsAny <string>(), LanguageServerKind.CSharp, It.IsAny <CompletionParams>(), It.IsAny <CancellationToken>()))
            .Callback <string, LanguageServerKind, CompletionParams, CancellationToken>((method, serverKind, completionParams, ct) =>
            {
                Assert.Equal(Methods.TextDocumentCompletionName, method);
                Assert.Equal(LanguageServerKind.CSharp, serverKind);
                languageServerCalled = true;
            })
            .Returns(Task.FromResult <SumType <CompletionItem[], CompletionList>?>(new[] { expectedItem }));

            var projectionResult = new ProjectionResult()
            {
                LanguageKind = RazorLanguageKind.Html,
                Position     = new Position(1, 7)
            };
            var previousCharacterProjection = new ProjectionResult()
            {
                LanguageKind  = RazorLanguageKind.CSharp,
                Position      = new Position(100, 10),
                PositionIndex = 1000,
                Uri           = virtualDocumentUri
            };
            var projectionProvider = new Mock <LSPProjectionProvider>();

            projectionProvider.Setup(p => p.GetProjectionAsync(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <Position>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(previousCharacterProjection));

            var completionHandler = new CompletionHandler(JoinableTaskContext, requestInvoker.Object, documentManager, projectionProvider.Object);

            // Act
            var(succeeded, result) = await completionHandler.TryGetProvisionalCompletionsAsync(completionRequest, Mock.Of <LSPDocumentSnapshot>(), projectionResult, CancellationToken.None).ConfigureAwait(false);

            // Assert
            Assert.True(succeeded);
            Assert.True(languageServerCalled);
            Assert.Equal(2, documentManager.UpdateVirtualDocumentCallCount);
            Assert.NotNull(result);
            var item = Assert.Single((CompletionItem[])result.Value);

            Assert.Equal(expectedItem.InsertText, item.InsertText);
        }