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);
        }
        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);
        }