@@ -42,6 +42,107 @@ public void GetBinding_ReturnsBindingWithInformation()
4242 Assert . Equal ( divTagHelper . TagMatchingRules , bindingResult . Mappings [ divTagHelper ] , TagMatchingRuleDescriptorComparer . Default ) ;
4343 }
4444
45+ [ Fact ]
46+ public void GetBinding_With_Multiple_TagNameRules_SingleHelper ( )
47+ {
48+ // Arrange
49+ var multiTagHelper = TagHelperDescriptorBuilder . Create ( "MultiTagHelper" , "SomeAssembly" )
50+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "div" ) )
51+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "a" ) )
52+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "img" ) )
53+ . Build ( ) ;
54+ var expectedDescriptors = new [ ] { multiTagHelper } ;
55+ var tagHelperBinder = new TagHelperBinder ( "" , expectedDescriptors ) ;
56+
57+ TestTagName ( "div" , multiTagHelper . TagMatchingRules [ 0 ] ) ;
58+ TestTagName ( "a" , multiTagHelper . TagMatchingRules [ 1 ] ) ;
59+ TestTagName ( "img" , multiTagHelper . TagMatchingRules [ 2 ] ) ;
60+ TestTagName ( "p" , null ) ;
61+ TestTagName ( "*" , null ) ;
62+ void TestTagName ( string tagName , TagMatchingRuleDescriptor expectedBindingResult )
63+ {
64+ // Act
65+ var bindingResult = tagHelperBinder . GetBinding (
66+
67+ tagName : tagName ,
68+ attributes : Array . Empty < KeyValuePair < string , string > > ( ) ,
69+ parentTagName : "body" ,
70+ parentIsTagHelper : false ) ;
71+
72+ // Assert
73+ if ( expectedBindingResult == null )
74+ {
75+ Assert . Null ( bindingResult ) ;
76+ return ;
77+ }
78+ else
79+ {
80+ Assert . NotNull ( bindingResult ) ;
81+ Assert . Equal ( expectedDescriptors , bindingResult . Descriptors , TagHelperDescriptorComparer . Default ) ;
82+
83+ Assert . Equal ( tagName , bindingResult . TagName ) ;
84+ var mapping = Assert . Single ( bindingResult . Mappings [ multiTagHelper ] ) ;
85+ Assert . Equal ( expectedBindingResult , mapping , TagMatchingRuleDescriptorComparer . Default ) ;
86+ }
87+ }
88+ }
89+
90+ [ Fact ]
91+ public void GetBinding_With_Multiple_TagNameRules_MultipleHelpers ( )
92+ {
93+ // Arrange
94+ var multiTagHelper1 = TagHelperDescriptorBuilder . Create ( "MultiTagHelper1" , "SomeAssembly" )
95+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "div" ) )
96+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "a" ) )
97+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "img" ) )
98+ . Build ( ) ;
99+
100+ var multiTagHelper2 = TagHelperDescriptorBuilder . Create ( "MultiTagHelper2" , "SomeAssembly" )
101+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "div" ) )
102+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "p" ) )
103+ . TagMatchingRuleDescriptor ( rule => rule . RequireTagName ( "table" ) )
104+ . Build ( ) ;
105+
106+ var tagHelperBinder = new TagHelperBinder ( "" , new [ ] { multiTagHelper1 , multiTagHelper2 } ) ;
107+
108+ TestTagName ( "div" , new [ ] { multiTagHelper1 , multiTagHelper2 } , new [ ] { multiTagHelper1 . TagMatchingRules [ 0 ] , multiTagHelper2 . TagMatchingRules [ 0 ] } ) ;
109+ TestTagName ( "a" , new [ ] { multiTagHelper1 } , new [ ] { multiTagHelper1 . TagMatchingRules [ 1 ] } ) ;
110+ TestTagName ( "img" , new [ ] { multiTagHelper1 } , new [ ] { multiTagHelper1 . TagMatchingRules [ 2 ] } ) ;
111+ TestTagName ( "p" , new [ ] { multiTagHelper2 } , new [ ] { multiTagHelper2 . TagMatchingRules [ 1 ] } ) ;
112+ TestTagName ( "table" , new [ ] { multiTagHelper2 } , new [ ] { multiTagHelper2 . TagMatchingRules [ 2 ] } ) ;
113+ TestTagName ( "*" , null , null ) ;
114+
115+
116+ void TestTagName ( string tagName , TagHelperDescriptor [ ] expectedDescriptors , TagMatchingRuleDescriptor [ ] expectedBindingResults )
117+ {
118+ // Act
119+ var bindingResult = tagHelperBinder . GetBinding (
120+ tagName : tagName ,
121+ attributes : Array . Empty < KeyValuePair < string , string > > ( ) ,
122+ parentTagName : "body" ,
123+ parentIsTagHelper : false ) ;
124+
125+ // Assert
126+ if ( expectedDescriptors is null )
127+ {
128+ Assert . Null ( bindingResult ) ;
129+ }
130+ else
131+ {
132+ Assert . NotNull ( bindingResult ) ;
133+ Assert . Equal ( expectedDescriptors , bindingResult . Descriptors , TagHelperDescriptorComparer . Default ) ;
134+
135+ Assert . Equal ( tagName , bindingResult . TagName ) ;
136+
137+ for ( int i = 0 ; i < expectedDescriptors . Length ; i ++ )
138+ {
139+ var mapping = Assert . Single ( bindingResult . Mappings [ expectedDescriptors [ i ] ] ) ;
140+ Assert . Equal ( expectedBindingResults [ i ] , mapping , TagMatchingRuleDescriptorComparer . Default ) ;
141+ }
142+ }
143+ }
144+ }
145+
45146 public static TheoryData RequiredParentData
46147 {
47148 get
0 commit comments