public void GetBoundTagHelperAttributes_MatchesPrefixedAttributeName() { // Arrange var documentDescriptors = new[] { TagHelperDescriptorBuilder.Create("TestType", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule.RequireTagName("a")) .BoundAttributeDescriptor(attribute => attribute .Name("asp-for") .TypeName(typeof(string).FullName) .PropertyName("AspFor")) .BoundAttributeDescriptor(attribute => attribute .Name("asp-route") .TypeName(typeof(IDictionary <string, string>).Namespace + "IDictionary<string, string>") .PropertyName("AspRoute") .AsDictionaryAttribute("asp-route-", typeof(string).FullName)) .Build() }; var expectedAttributeDescriptors = new[] { documentDescriptors[0].BoundAttributes.Last() }; var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors); var service = new DefaultTagHelperFactsService(); var binding = service.GetTagHelperBinding(documentContext, "a", Enumerable.Empty <KeyValuePair <string, string> >(), parentTag: null, parentIsTagHelper: false); // Act var descriptors = service.GetBoundTagHelperAttributes(documentContext, "asp-route-something", binding); // Assert Assert.Equal(expectedAttributeDescriptors, descriptors, BoundAttributeDescriptorComparer.Default); }
public void GetBoundTagHelperAttributes_MatchesAttributeName() { // Arrange var documentDescriptors = new[] { TagHelperDescriptorBuilder.Create("TestType", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule.RequireTagName("input")) .BoundAttributeDescriptor(attribute => attribute .Name("asp-for") .TypeName(typeof(string).FullName) .PropertyName("AspFor")) .BoundAttributeDescriptor(attribute => attribute .Name("asp-extra") .TypeName(typeof(string).FullName) .PropertyName("AspExtra")) .Build() }; var expectedAttributeDescriptors = new[] { documentDescriptors[0].BoundAttributes.First() }; var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors); var service = new DefaultTagHelperFactsService(); var binding = service.GetTagHelperBinding(documentContext, "input", Enumerable.Empty <KeyValuePair <string, string> >(), parentTag: null, parentIsTagHelper: false); // Act var descriptors = service.GetBoundTagHelperAttributes(documentContext, "asp-for", binding); // Assert Assert.Equal(expectedAttributeDescriptors, descriptors, BoundAttributeDescriptorComparer.CaseSensitive); }
public void GetTagHelperBinding_WorksAsExpected() { // Arrange var documentDescriptors = new[] { TagHelperDescriptorBuilder.Create("TestType", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule .RequireTagName("a") .RequireAttributeDescriptor(attribute => attribute.Name("asp-for"))) .BoundAttributeDescriptor(attribute => attribute .Name("asp-for") .TypeName(typeof(string).FullName) .PropertyName("AspFor")) .BoundAttributeDescriptor(attribute => attribute .Name("asp-route") .TypeName(typeof(IDictionary <string, string>).Namespace + "IDictionary<string, string>") .PropertyName("AspRoute") .AsDictionaryAttribute("asp-route-", typeof(string).FullName)) .Build(), TagHelperDescriptorBuilder.Create("TestType", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule.RequireTagName("input")) .BoundAttributeDescriptor(attribute => attribute .Name("asp-for") .TypeName(typeof(string).FullName) .PropertyName("AspFor")) .Build(), }; var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors); var service = new DefaultTagHelperFactsService(); var attributes = new[] { new KeyValuePair <string, string>("asp-for", "Name") }; // Act var binding = service.GetTagHelperBinding(documentContext, "a", attributes, parentTag: "p", parentIsTagHelper: false); // Assert var descriptor = Assert.Single(binding.Descriptors); Assert.Equal(documentDescriptors[0], descriptor, TagHelperDescriptorComparer.Default); var boundRule = Assert.Single(binding.Mappings[descriptor]); Assert.Equal(documentDescriptors[0].TagMatchingRules.First(), boundRule, TagMatchingRuleDescriptorComparer.Default); }
public void GetTagHelperBinding_DoesNotAllowOptOutCharacterPrefix() { // Arrange var documentDescriptors = new[] { TagHelperDescriptorBuilder.Create("TestType", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule.RequireTagName("*")) .Build() }; var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors); var service = new DefaultTagHelperFactsService(); // Act var binding = service.GetTagHelperBinding(documentContext, "!a", Enumerable.Empty <KeyValuePair <string, string> >(), parentTag: null, parentIsTagHelper: false); // Assert Assert.Null(binding); }