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); // Act var descriptors = service.GetBoundTagHelperAttributes(documentContext, "asp-route-something", binding); // Assert Assert.Equal(expectedAttributeDescriptors, descriptors, BoundAttributeDescriptorComparer.CaseSensitive); }
private static DefaultTagHelperCompletionService CreateTagHelperCompletionFactsService() { var tagHelperFactService = new DefaultTagHelperFactsService(); var completionFactService = new DefaultTagHelperCompletionService(tagHelperFactService); return(completionFactService); }
public void GetTagHelpersGivenParent_RestrictsTagHelpersBasedOnParent() { // Arrange var expectedDescriptors = new[] { TagHelperDescriptorBuilder.Create("TestType", "TestAssembly") .TagMatchingRuleDescriptor( rule => rule .RequireTagName("p") .RequireParentTag("div")) .Build() }; var documentDescriptors = new[] { expectedDescriptors[0], TagHelperDescriptorBuilder.Create("TestType2", "TestAssembly") .TagMatchingRuleDescriptor( rule => rule .RequireTagName("strong") .RequireParentTag("p")) .Build() }; var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors); var service = new DefaultTagHelperFactsService(); // Act var descriptors = service.GetTagHelpersGivenParent(documentContext, "div"); // Assert Assert.Equal(expectedDescriptors, descriptors, TagHelperDescriptorComparer.CaseSensitive); }
public void GetTagHelpersGivenParent_AllowsRootParentTagForParentRestrictedTagHelperDescriptors() { // Arrange var documentDescriptors = new[] { TagHelperDescriptorBuilder.Create("DivTagHelper", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule.RequireTagName("div")) .Build(), TagHelperDescriptorBuilder.Create("PTagHelper", "TestAssembly") .TagMatchingRuleDescriptor(rule => rule .RequireTagName("p") .RequireParentTag("body")) .Build() }; var documentContext = TagHelperDocumentContext.Create(string.Empty, documentDescriptors); var service = new DefaultTagHelperFactsService(); // Act var descriptors = service.GetTagHelpersGivenParent(documentContext, parentTag: null /* root */); // Assert var descriptor = Assert.Single(descriptors); Assert.Equal(documentDescriptors[0], descriptor, TagHelperDescriptorComparer.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"); // Assert var descriptor = Assert.Single(binding.Descriptors); Assert.Equal(documentDescriptors[0], descriptor, TagHelperDescriptorComparer.CaseSensitive); var boundRule = Assert.Single(binding.GetBoundRules(descriptor)); Assert.Equal(documentDescriptors[0].TagMatchingRules.First(), boundRule, TagMatchingRuleDescriptorComparer.CaseSensitive); }
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); // Assert Assert.Null(binding); }
public void GetTagHelpersGivenTag_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 descriptors = service.GetTagHelpersGivenTag(documentContext, "!strong", parentTag: null); // Assert Assert.Empty(descriptors); }