예제 #1
0
        public async Task TryResolveProximityExpressionsAsync_MappableCSharpLocation_ReturnsExpressions()
        {
            // Arrange
            var hostDocumentPosition   = GetPosition(ValidProximityExpressionRoot, HostTextbuffer);
            var csharpDocumentPosition = GetPosition(ValidProximityExpressionRoot, CSharpTextBuffer);
            var csharpDocumentIndex    = CSharpTextBuffer.CurrentSnapshot.GetText().IndexOf(ValidProximityExpressionRoot, StringComparison.Ordinal);
            var projectionProvider     = new TestLSPProjectionProvider(
                DocumentUri,
                new Dictionary <Position, ProjectionResult>()
            {
                [hostDocumentPosition] = new ProjectionResult()
                {
                    LanguageKind        = RazorLanguageKind.CSharp,
                    HostDocumentVersion = 0,
                    Position            = csharpDocumentPosition,
                    PositionIndex       = csharpDocumentIndex,
                }
            });
            var resolver = CreateResolverWith(projectionProvider: projectionProvider);

            // Act
            var expressions = await resolver.TryResolveProximityExpressionsAsync(HostTextbuffer, hostDocumentPosition.Line, hostDocumentPosition.Character, CancellationToken.None);

            // Assert
            Assert.NotEmpty(expressions);
        }
예제 #2
0
        public async Task TryResolveBreakpointRangeAsync_UnmappableCSharpBreakpointLocation_ReturnsNull()
        {
            // Arrange
            var hostDocumentPosition   = GetPosition(ValidBreakpointCSharp, HostTextbuffer);
            var csharpDocumentPosition = GetPosition(ValidBreakpointCSharp, CSharpTextBuffer);
            var csharpDocumentIndex    = CSharpTextBuffer.CurrentSnapshot.GetText().IndexOf(ValidBreakpointCSharp, StringComparison.Ordinal);
            var projectionProvider     = new TestLSPProjectionProvider(
                DocumentUri,
                new Dictionary <Position, ProjectionResult>()
            {
                [hostDocumentPosition] = new ProjectionResult()
                {
                    LanguageKind        = RazorLanguageKind.CSharp,
                    HostDocumentVersion = 0,
                    Position            = csharpDocumentPosition,
                    PositionIndex       = csharpDocumentIndex,
                }
            });
            var resolver = CreateResolverWith(projectionProvider: projectionProvider);

            // Act
            var breakpointRange = await resolver.TryResolveBreakpointRangeAsync(HostTextbuffer, hostDocumentPosition.Line, hostDocumentPosition.Character, CancellationToken.None);

            // Assert
            Assert.Null(breakpointRange);
        }
예제 #3
0
        public async Task TryResolveBreakpointRangeAsync_MappableCSharpBreakpointLocation_ReturnsHostBreakpointLocation()
        {
            // Arrange
            var hostDocumentPosition   = GetPosition(ValidBreakpointCSharp, HostTextbuffer);
            var csharpDocumentPosition = GetPosition(ValidBreakpointCSharp, CSharpTextBuffer);
            var csharpDocumentIndex    = CSharpTextBuffer.CurrentSnapshot.GetText().IndexOf(ValidBreakpointCSharp, StringComparison.Ordinal);
            var projectionProvider     = new TestLSPProjectionProvider(
                DocumentUri,
                new Dictionary <Position, ProjectionResult>()
            {
                [hostDocumentPosition] = new ProjectionResult()
                {
                    LanguageKind        = RazorLanguageKind.CSharp,
                    HostDocumentVersion = 0,
                    Position            = csharpDocumentPosition,
                    PositionIndex       = csharpDocumentIndex,
                }
            });
            var expectedCSharpBreakpointRange = new Range()
            {
                Start = csharpDocumentPosition,
                End   = new Position(csharpDocumentPosition.Line, csharpDocumentPosition.Character + ValidBreakpointCSharp.Length),
            };
            var hostBreakpointRange = new Range()
            {
                Start = hostDocumentPosition,
                End   = new Position(hostDocumentPosition.Line, hostDocumentPosition.Character + ValidBreakpointCSharp.Length),
            };
            var mappingProvider = new TestLSPDocumentMappingProvider(
                new Dictionary <Range, RazorMapToDocumentRangesResponse>()
            {
                [expectedCSharpBreakpointRange] = new RazorMapToDocumentRangesResponse()
                {
                    HostDocumentVersion = 0,
                    Ranges = new[]
                    {
                        hostBreakpointRange,
                    },
                }
            });
            var resolver = CreateResolverWith(projectionProvider: projectionProvider, documentMappingProvider: mappingProvider);

            // Act
            var breakpointRange = await resolver.TryResolveBreakpointRangeAsync(HostTextbuffer, hostDocumentPosition.Line, hostDocumentPosition.Character, CancellationToken.None);

            // Assert
            Assert.Equal(hostBreakpointRange, breakpointRange);
        }
예제 #4
0
        public async Task TryResolveProximityExpressionsAsync_RazorProjectedLocation_ReturnsNull()
        {
            // Arrange
            var position           = new Position(line: 0, character: 2);
            var projectionProvider = new TestLSPProjectionProvider(
                DocumentUri,
                new Dictionary <Position, ProjectionResult>()
            {
                [position] = new ProjectionResult()
                {
                    LanguageKind        = RazorLanguageKind.Razor,
                    HostDocumentVersion = 0,
                    Position            = position,
                }
            });
            var resolver = CreateResolverWith(projectionProvider: projectionProvider);

            // Act
            var expressions = await resolver.TryResolveProximityExpressionsAsync(HostTextbuffer, position.Line, position.Character, CancellationToken.None);

            // Assert
            Assert.Null(expressions);
        }