Exemple #1
0
        public async Task GetNavigatePositionAsync_TagHelperProperty_IgnoreInnerProperty()
        {
            // Arrange
            var content = @"

<div>@Title</div>

@code
{
    private class NotTheDroidsYoureLookingFor
    {
        public string Title { get; set; }
    }

    public string [|Title|] { get; set; }
}
";

            TestFileMarkupParser.GetSpan(content, out content, out var selection);

            SetupDocument(out var codeDocument, out _, content);
            var expectedRange = selection.AsRange(codeDocument.GetSourceText());

            var mappingService = new DefaultRazorDocumentMappingService(LoggerFactory);

            // Act II
            var range = await RazorDefinitionEndpoint.TryGetPropertyRangeAsync(codeDocument, "Title", mappingService, Logger, CancellationToken.None).ConfigureAwait(false);

            Assert.NotNull(range);
            Assert.Equal(expectedRange, range);
        }
Exemple #2
0
        public async Task GetNavigatePositionAsync_TagHelperProperty_CorrectRange2()
        {
            // Arrange
            var content = @"

<div>@Title</div>

@code
{
    [Microsoft.AspNetCore.Components.Parameter]
    public string [|Title|] { get; set; }
}
";

            TestFileMarkupParser.GetSpan(content, out content, out var selection);

            SetupDocument(out var codeDocument, out _, content);
            var expectedRange = selection.AsRange(codeDocument.GetSourceText());

            var mappingService = new DefaultRazorDocumentMappingService(LoggerFactory);

            // Act II
            var range = await RazorDefinitionEndpoint.TryGetPropertyRangeAsync(codeDocument, "Title", mappingService, Logger, CancellationToken.None).ConfigureAwait(false);

            Assert.NotNull(range);
            Assert.Equal(expectedRange, range);
        }
        public async Task GetOriginTagHelperBindingAsync_TagHelper_MultipleAttributes()
        {
            // Arrange
            var content = @"@addTagHelper *, TestAssembly
<Component1 @test=""Increment"" @minimized></Component1>
@code {
    public void Increment()
    {
    }
}";

            SetupDocument(out var codeDocument, out var documentSnapshot, content);
            var position = new Position(1, 2);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(
                documentSnapshot, codeDocument, position, LoggerFactory.CreateLogger("RazorDefinitionEndpoint")).ConfigureAwait(false);

            // Assert
            Assert.Equal("Component1", binding.TagName);
            Assert.Collection(binding.Descriptors,
                              d => Assert.Equal("Component1TagHelper", d.Name),
                              d => Assert.Equal("TestDirectiveAttribute", d.Name),
                              d => Assert.Equal("MinimizedDirectiveAttribute", d.Name));
        }
        public async Task GetOriginTagHelperBindingAsync_TagHelper_AttributeValue_ReturnsNull()
        {
            // Arrange
            SetupDocument(out var codeDocument, out var documentSnapshot);
            var position = new Position(1, 24);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(documentSnapshot, codeDocument, position).ConfigureAwait(false);

            // Assert
            Assert.Null(binding);
        }
        public async Task GetOriginTagHelperBindingAsync_TagHelper_AfterAttributeEquals_ReturnsNull()
        {
            // Arrange
            SetupDocument(out var codeDocument, out var documentSnapshot);
            var position = new Position(1, 18);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(
                documentSnapshot, codeDocument, position, LoggerFactory.CreateLogger("RazorDefinitionEndpoint")).ConfigureAwait(false);

            // Assert
            Assert.Null(binding);
        }
        public async Task GetOriginTagHelperBindingAsync_HTML_MarkupElement()
        {
            // Arrange
            var content = $"@addTagHelper *, TestAssembly{Environment.NewLine}<p><strong></strong></p>";

            SetupDocument(out var codeDocument, out var documentSnapshot, content);
            var position = new Position(1, 6);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(documentSnapshot, codeDocument, position).ConfigureAwait(false);

            // Assert
            Assert.Null(binding);
        }
Exemple #7
0
        public async Task GetOriginTagHelperBindingAsync_TagHelper_EndTag_WithAttribute()
        {
            // Arrange
            SetupDocument(out var codeDocument, out var documentSnapshot);
            var position = new Position(1, 35);

            // Act
            var(descriptor, attributeDescriptor) = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(
                documentSnapshot, codeDocument, position, LoggerFactory.CreateLogger("RazorDefinitionEndpoint")).ConfigureAwait(false);

            // Assert
            Assert.Equal("Component1TagHelper", descriptor.Name);
            Assert.Null(attributeDescriptor);
        }
        public async Task GetOriginTagHelperBindingAsync_TagHelper_EndTag_WithAttribute()
        {
            // Arrange
            SetupDocument(out var codeDocument, out var documentSnapshot);
            var position = new Position(1, 35);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(documentSnapshot, codeDocument, position).ConfigureAwait(false);

            // Assert
            Assert.Equal("Component1", binding.TagName);
            Assert.Collection(binding.Descriptors,
                              d => Assert.Equal("Component1TagHelper", d.Name),
                              d => Assert.Equal("TestDirectiveAttribute", d.Name));
        }
Exemple #9
0
        public async Task GetOriginTagHelperBindingAsync_TagHelper_Element()
        {
            // Arrange
            var txt              = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1></test1>";
            var srcText          = SourceText.From(txt);
            var codeDocument     = CreateCodeDocument(txt, isRazorFile: false, DefaultTagHelpers);
            var documentSnapshot = Mock.Of <DocumentSnapshot>(d => d.GetTextAsync() == Task.FromResult(srcText), MockBehavior.Strict);
            var position         = new Position(1, 2);

            // Act
            var(descriptor, attributeDescriptor) = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(
                documentSnapshot, codeDocument, position, LoggerFactory.CreateLogger("RazorDefinitionEndpoint")).ConfigureAwait(false);

            // Assert
            Assert.Equal("Test1TagHelper", descriptor.Name);
            Assert.Null(attributeDescriptor);
        }
        public async Task GetOriginTagHelperBindingAsync_TagHelper_Element()
        {
            // Arrange
            var txt              = $"@addTagHelper *, TestAssembly{Environment.NewLine}<test1></test1>";
            var srcText          = SourceText.From(txt);
            var codeDocument     = CreateCodeDocument(txt, DefaultTagHelpers);
            var documentSnapshot = Mock.Of <DocumentSnapshot>(d => d.GetTextAsync() == Task.FromResult(srcText), MockBehavior.Strict);
            var position         = new Position(1, 2);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(documentSnapshot, codeDocument, position).ConfigureAwait(false);

            // Assert
            Assert.Equal("test1", binding.TagName);
            var descriptor = Assert.Single(binding.Descriptors);

            Assert.Equal("Test1TagHelper", descriptor.Name);
        }
Exemple #11
0
        public async Task GetOriginTagHelperBindingAsync_TagHelper_MalformedAttribute()
        {
            // Arrange
            var content = @"@addTagHelper *, TestAssembly
<Component1 @test=""Increment></Component1>
@code {
    public void Increment()
    {
    }
}";

            SetupDocument(out var codeDocument, out var documentSnapshot, content);
            var position = new Position(1, 2);

            // Act
            var(descriptor, attributeDescriptor) = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(
                documentSnapshot, codeDocument, position, LoggerFactory.CreateLogger("RazorDefinitionEndpoint")).ConfigureAwait(false);

            // Assert
            Assert.Equal("Component1TagHelper", descriptor.Name);
            Assert.Null(attributeDescriptor);
        }
        public async Task GetOriginTagHelperBindingAsync_TagHelper_MalformedElement()
        {
            // Arrange
            var content = @"@addTagHelper *, TestAssembly
<Component1</Component1>
@code {
    public void Increment()
    {
    }
}";

            SetupDocument(out var codeDocument, out var documentSnapshot, content);
            var position = new Position(1, 2);

            // Act
            var binding = await RazorDefinitionEndpoint.GetOriginTagHelperBindingAsync(documentSnapshot, codeDocument, position).ConfigureAwait(false);

            // Assert
            Assert.Equal("Component1", binding.TagName);
            var descriptor = Assert.Single(binding.Descriptors);

            Assert.Equal("Component1TagHelper", descriptor.Name);
        }