diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBinding.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBinding.cs deleted file mode 100644 index 2d4b0d99d9..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperBinding.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Razor.Language.Legacy -{ - public sealed class TagHelperBinding - { - public IReadOnlyDictionary> _mappings; - - internal TagHelperBinding(IReadOnlyDictionary> mappings) - { - _mappings = mappings; - Descriptors = _mappings.Keys; - } - - public IEnumerable Descriptors { get; } - - public IEnumerable GetBoundRules(TagHelperDescriptor descriptor) - { - return _mappings[descriptor]; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinder.cs b/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinder.cs index 15a8ce82f2..d75023fd10 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinder.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Razor.Language.Legacy; namespace Microsoft.AspNetCore.Razor.Language { @@ -97,9 +96,14 @@ namespace Microsoft.AspNetCore.Razor.Language return null; } - var tagMappingResult = new TagHelperBinding(applicableDescriptorMappings); + var tagHelperBinding = new TagHelperBinding( + tagName, + attributes, + parentTagName, + applicableDescriptorMappings, + _tagHelperPrefix); - return tagMappingResult; + return tagHelperBinding; } private void Register(TagHelperDescriptor descriptor) diff --git a/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinding.cs b/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinding.cs new file mode 100644 index 0000000000..6e5119a1a3 --- /dev/null +++ b/src/Microsoft.AspNetCore.Razor.Language/TagHelperBinding.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Razor.Language +{ + public sealed class TagHelperBinding + { + private IReadOnlyDictionary> _mappings; + + internal TagHelperBinding( + string tagName, + IEnumerable> attributes, + string parentTagName, + IReadOnlyDictionary> mappings, + string tagHelperPrefix) + { + TagName = tagName; + Attributes = attributes; + ParentTagName = parentTagName; + TagHelperPrefix = tagHelperPrefix; + + _mappings = mappings; + } + + public IEnumerable Descriptors => _mappings.Keys; + + public string TagName { get; } + + public string ParentTagName { get; } + + public IEnumerable> Attributes { get; } + + public string TagHelperPrefix { get; } + + public IEnumerable GetBoundRules(TagHelperDescriptor descriptor) + { + return _mappings[descriptor]; + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TagHelperBinderTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TagHelperBinderTest.cs index 09301d11c9..0dc5d70f2e 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TagHelperBinderTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TagHelperBinderTest.cs @@ -10,6 +10,35 @@ namespace Microsoft.AspNetCore.Razor.Language { public class TagHelperBinderTest { + [Fact] + public void GetBinding_ReturnsBindingWithInformation() + { + // Arrange + var divTagHelper = TagHelperDescriptorBuilder.Create("DivTagHelper", "SomeAssembly") + .TagMatchingRule(rule => rule.RequireTagName("div")) + .Build(); + var expectedDescriptors = new[] { divTagHelper }; + var expectedAttributes = new[] + { + new KeyValuePair("class", "something") + }; + var tagHelperBinder = new TagHelperBinder("th:", expectedDescriptors); + + // Act + var bindingResult = tagHelperBinder.GetBinding( + tagName: "th:div", + attributes: expectedAttributes, + parentTagName: "body"); + + // Assert + Assert.Equal(expectedDescriptors, bindingResult.Descriptors, TagHelperDescriptorComparer.CaseSensitive); + Assert.Equal("th:div", bindingResult.TagName); + Assert.Equal("body", bindingResult.ParentTagName); + Assert.Equal(expectedAttributes, bindingResult.Attributes); + Assert.Equal("th:", bindingResult.TagHelperPrefix); + Assert.Equal(divTagHelper.TagMatchingRules, bindingResult.GetBoundRules(divTagHelper), TagMatchingRuleComparer.CaseSensitive); + } + public static TheoryData RequiredParentData { get @@ -107,7 +136,7 @@ namespace Microsoft.AspNetCore.Razor.Language .TagMatchingRule(rule => rule .RequireTagName("input") - .RequireAttribute(attribute => + .RequireAttribute(attribute => attribute .Name("nodashprefix") .NameComparisonMode(RequiredAttributeDescriptor.NameComparisonMode.PrefixMatch))) @@ -129,7 +158,7 @@ namespace Microsoft.AspNetCore.Razor.Language .TagMatchingRule(rule => rule .RequireTagName(TagHelperMatchingConventions.ElementCatchAllName) - .RequireAttribute(attribute => + .RequireAttribute(attribute => attribute .Name("prefix-") .NameComparisonMode(RequiredAttributeDescriptor.NameComparisonMode.PrefixMatch))) @@ -406,7 +435,7 @@ namespace Microsoft.AspNetCore.Razor.Language // Arrange var divDescriptor = TagHelperDescriptorBuilder.Create("foo1", "SomeAssembly") .TagMatchingRule(rule => rule.RequireTagName("div")) - .Build(); + .Build(); var descriptors = new TagHelperDescriptor[] { divDescriptor, divDescriptor }; var tagHelperBinder = new TagHelperBinder(null, descriptors);