Exemplo n.º 1
0
        public async Task MapSpans_WithinRange_ReturnsMapping()
        {
            // Arrange
            var called = false;

            var textSpan = new TextSpan(1, 10);
            var spans    = new TextSpan[] { textSpan };

            var documentSnapshot = new Mock <LSPDocumentSnapshot>(MockBehavior.Strict);

            documentSnapshot.SetupGet(doc => doc.Uri).Returns(_mockDocumentUri);

            var textSnapshot = new StringTextSnapshot(s_mockGeneratedContent, 1);

            var textSpanAsRange = textSpan.AsRange(_sourceTextGenerated);
            var mappedRange     = new Range()
            {
                Start = new Position(2, 1),
                End   = new Position(2, 11)
            };

            var documentMappingProvider = new Mock <LSPDocumentMappingProvider>(MockBehavior.Strict);
            var mappingResult           = new RazorMapToDocumentRangesResponse()
            {
                Ranges = new Range[] { mappedRange }
            };

            documentMappingProvider.Setup(dmp => dmp.MapToDocumentRangesAsync(It.IsAny <RazorLanguageKind>(), It.IsAny <Uri>(), It.IsAny <Range[]>(), It.IsAny <CancellationToken>()))
            .Callback <RazorLanguageKind, Uri, Range[], CancellationToken>((languageKind, uri, ranges, ct) =>
            {
                Assert.Equal(RazorLanguageKind.CSharp, languageKind);
                Assert.Equal(_mockDocumentUri, uri);
                Assert.Single(ranges, textSpanAsRange);
                called = true;
            })
            .Returns(Task.FromResult(mappingResult));

            var service = new RazorLSPSpanMappingService(documentMappingProvider.Object, documentSnapshot.Object, textSnapshot);

            var expectedSpan         = mappedRange.AsTextSpan(_sourceTextRazor);
            var expectedLinePosition = _sourceTextRazor.Lines.GetLinePositionSpan(expectedSpan);
            var expectedFilePath     = _mockDocumentUri.LocalPath;
            var expectedResult       = (expectedFilePath, expectedLinePosition, expectedSpan);

            // Act
            var result = await service.MapSpansAsyncTest(spans, _sourceTextGenerated, _sourceTextRazor).ConfigureAwait(false);

            // Assert
            Assert.True(called);
            Assert.Single(result, expectedResult);
        }
Exemplo n.º 2
0
        public void MapSpans_GetMappedSpanResults_MappingErrorReturnsDefaultMappedSpan()
        {
            // Arrange
            var documentSnapshot = new Mock <LSPDocumentSnapshot>(MockBehavior.Strict);

            documentSnapshot.SetupGet(doc => doc.Uri).Returns(_mockDocumentUri);
            var sourceTextRazor = SourceText.From("");
            var response        = new RazorMapToDocumentRangesResponse {
                Ranges = new Range[] { Extensions.RangeExtensions.UndefinedRange }
            };

            // Act
            var results = RazorLSPSpanMappingService.GetMappedSpanResults(documentSnapshot.Object, sourceTextRazor, response);

            // Assert
            Assert.True(results.Single().IsDefault);
        }
Exemplo n.º 3
0
        public async Task MapSpans_OutsideRange_ReturnsEmpty()
        {
            // Arrange
            var called = false;

            var textSpan = new TextSpan(10, 10);
            var spans    = new TextSpan[] { textSpan };

            var documentSnapshot = new Mock <LSPDocumentSnapshot>(MockBehavior.Strict);

            documentSnapshot.SetupGet(doc => doc.Uri).Returns(_mockDocumentUri);

            var textSnapshot = new StringTextSnapshot(s_mockGeneratedContent, 1);

            var textSpanAsRange = textSpan.AsRange(_sourceTextGenerated);

            var documentMappingProvider = new Mock <LSPDocumentMappingProvider>(MockBehavior.Strict);

            documentMappingProvider.Setup(dmp => dmp.MapToDocumentRangesAsync(It.IsAny <RazorLanguageKind>(), It.IsAny <Uri>(), It.IsAny <Range[]>(), It.IsAny <CancellationToken>()))
            .Callback <RazorLanguageKind, Uri, Range[], CancellationToken>((languageKind, uri, ranges, ct) =>
            {
                Assert.Equal(RazorLanguageKind.CSharp, languageKind);
                Assert.Equal(_mockDocumentUri, uri);
                Assert.Single(ranges, textSpanAsRange);
                called = true;
            })
            .Returns(Task.FromResult <RazorMapToDocumentRangesResponse>(null));

            var service = new RazorLSPSpanMappingService(documentMappingProvider.Object, documentSnapshot.Object, textSnapshot);

            // Act
            var result = await service.MapSpansAsyncTest(spans, _sourceTextGenerated, _sourceTextRazor).ConfigureAwait(false);

            // Assert
            Assert.True(called);
            Assert.Empty(result);
        }