Skip to content

Commit bfc675c

Browse files
Clean up TestRequiredAttributeDescriptorBuilderExtensions
- Enable nullability - Remove unnecessary argument null checks - Add optional parameter to Name() extension method taking a RequiredAttributeNameComparison. - Update callers of Name() to pass optional parameter and remove calls to NameComparison() - Add optional parameter to Value() extension method taking a RequiredAttributeValueComparison. - Update callers of Value() to pass optional parameter and remove calls to ValueComparison()
1 parent b3a0270 commit bfc675c

File tree

9 files changed

+89
-172
lines changed

9 files changed

+89
-172
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorTagHelperBinderPhaseTest.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,10 @@ public void Execute_DirectiveWithoutQuotes_RewritesTagHelpers_TagHelperMatchesEl
265265
[
266266
ruleBuilder => ruleBuilder
267267
.RequireAttributeDescriptor(attribute => attribute
268-
.Name("a")
269-
.NameComparison(RequiredAttributeNameComparison.FullMatch)),
268+
.Name("a", RequiredAttributeNameComparison.FullMatch)),
270269
ruleBuilder => ruleBuilder
271270
.RequireAttributeDescriptor(attribute => attribute
272-
.Name("b")
273-
.NameComparison(RequiredAttributeNameComparison.FullMatch)),
271+
.Name("b", RequiredAttributeNameComparison.FullMatch)),
274272
]);
275273

276274
var content = @"
@@ -309,12 +307,10 @@ public void Execute_DirectiveWithQuotes_RewritesTagHelpers_TagHelperMatchesEleme
309307
[
310308
ruleBuilder => ruleBuilder
311309
.RequireAttributeDescriptor(attribute => attribute
312-
.Name("a")
313-
.NameComparison(RequiredAttributeNameComparison.FullMatch)),
310+
.Name("a", RequiredAttributeNameComparison.FullMatch)),
314311
ruleBuilder => ruleBuilder
315312
.RequireAttributeDescriptor(attribute => attribute
316-
.Name("b")
317-
.NameComparison(RequiredAttributeNameComparison.FullMatch)),
313+
.Name("b", RequiredAttributeNameComparison.FullMatch)),
318314
]);
319315

320316
var content = @"

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRequiredAttributeDescriptorBuilderTest.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public void Build_DisplayNameIsName_NameComparisonFullMatch()
1616
var tagMatchingRuleBuilder = new TagMatchingRuleDescriptorBuilder(tagHelperBuilder);
1717
var builder = new RequiredAttributeDescriptorBuilder(tagMatchingRuleBuilder);
1818

19-
builder
20-
.Name("asp-action")
21-
.NameComparison(RequiredAttributeNameComparison.FullMatch);
19+
builder.Name("asp-action", RequiredAttributeNameComparison.FullMatch);
2220

2321
// Act
2422
var descriptor = builder.Build();
@@ -35,9 +33,7 @@ public void Build_DisplayNameIsNameWithDots_NameComparisonPrefixMatch()
3533
var tagMatchingRuleBuilder = new TagMatchingRuleDescriptorBuilder(tagHelperBuilder);
3634
var builder = new RequiredAttributeDescriptorBuilder(tagMatchingRuleBuilder);
3735

38-
builder
39-
.Name("asp-route-")
40-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch);
36+
builder.Name("asp-route-", RequiredAttributeNameComparison.PrefixMatch);
4137

4238
// Act
4339
var descriptor = builder.Build();

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/TestTagHelperDescriptors.cs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ public static IEnumerable<TagHelperDescriptor> CssSelectorTagHelperDescriptors
116116
{
117117
builder => builder
118118
.RequireAttributeDescriptor(attribute => attribute
119-
.Name("href")
120-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
121-
.Value("~/")
122-
.ValueComparison(RequiredAttributeValueComparison.FullMatch)),
119+
.Name("href", RequiredAttributeNameComparison.FullMatch)
120+
.Value("~/", RequiredAttributeValueComparison.FullMatch)),
123121
}),
124122
CreateTagHelperDescriptor(
125123
tagName: "a",
@@ -129,15 +127,11 @@ public static IEnumerable<TagHelperDescriptor> CssSelectorTagHelperDescriptors
129127
{
130128
builder => builder
131129
.RequireAttributeDescriptor(attribute => attribute
132-
.Name("href")
133-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
134-
.Value("~/")
135-
.ValueComparison(RequiredAttributeValueComparison.PrefixMatch))
130+
.Name("href", RequiredAttributeNameComparison.FullMatch)
131+
.Value("~/", RequiredAttributeValueComparison.PrefixMatch))
136132
.RequireAttributeDescriptor(attribute => attribute
137-
.Name("href")
138-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
139-
.Value("?hello=world")
140-
.ValueComparison(RequiredAttributeValueComparison.SuffixMatch)),
133+
.Name("href", RequiredAttributeNameComparison.FullMatch)
134+
.Value("?hello=world", RequiredAttributeValueComparison.SuffixMatch)),
141135
}),
142136
CreateTagHelperDescriptor(
143137
tagName: "input",
@@ -151,10 +145,8 @@ public static IEnumerable<TagHelperDescriptor> CssSelectorTagHelperDescriptors
151145
{
152146
builder => builder
153147
.RequireAttributeDescriptor(attribute => attribute
154-
.Name("type")
155-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
156-
.Value("text")
157-
.ValueComparison(RequiredAttributeValueComparison.FullMatch)),
148+
.Name("type", RequiredAttributeNameComparison.FullMatch)
149+
.Value("text", RequiredAttributeValueComparison.FullMatch)),
158150
}),
159151
CreateTagHelperDescriptor(
160152
tagName: "input",
@@ -168,8 +160,7 @@ public static IEnumerable<TagHelperDescriptor> CssSelectorTagHelperDescriptors
168160
{
169161
builder => builder
170162
.RequireAttributeDescriptor(attribute => attribute
171-
.Name("ty")
172-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch)),
163+
.Name("ty", RequiredAttributeNameComparison.PrefixMatch)),
173164
}),
174165
CreateTagHelperDescriptor(
175166
tagName: "*",
@@ -179,10 +170,8 @@ public static IEnumerable<TagHelperDescriptor> CssSelectorTagHelperDescriptors
179170
{
180171
builder => builder
181172
.RequireAttributeDescriptor(attribute => attribute
182-
.Name("href")
183-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
184-
.Value("~/")
185-
.ValueComparison(RequiredAttributeValueComparison.PrefixMatch)),
173+
.Name("href", RequiredAttributeNameComparison.FullMatch)
174+
.Value("~/", RequiredAttributeValueComparison.PrefixMatch)),
186175
}),
187176
CreateTagHelperDescriptor(
188177
tagName: "*",
@@ -192,8 +181,7 @@ public static IEnumerable<TagHelperDescriptor> CssSelectorTagHelperDescriptors
192181
{
193182
builder => builder
194183
.RequireAttributeDescriptor(attribute => attribute
195-
.Name("type")
196-
.NameComparison(RequiredAttributeNameComparison.FullMatch)),
184+
.Name("type", RequiredAttributeNameComparison.FullMatch)),
197185
}),
198186
};
199187
}

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TagHelperBinderTest.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,48 +225,38 @@ public static TheoryData RequiredAttributeData
225225
get
226226
{
227227
var divDescriptor = TagHelperDescriptorBuilder.Create("DivTagHelper", "SomeAssembly")
228-
.TagMatchingRuleDescriptor(rule =>
229-
rule
228+
.TagMatchingRuleDescriptor(rule => rule
230229
.RequireTagName("div")
231230
.RequireAttributeDescriptor(attribute => attribute.Name("style")))
232231
.Build();
233232
var inputDescriptor = TagHelperDescriptorBuilder.Create("InputTagHelper", "SomeAssembly")
234-
.TagMatchingRuleDescriptor(rule =>
235-
rule
233+
.TagMatchingRuleDescriptor(rule => rule
236234
.RequireTagName("input")
237235
.RequireAttributeDescriptor(attribute => attribute.Name("class"))
238236
.RequireAttributeDescriptor(attribute => attribute.Name("style")))
239237
.Build();
240238
var inputWildcardPrefixDescriptor = TagHelperDescriptorBuilder.Create("InputWildCardAttribute", "SomeAssembly")
241-
.TagMatchingRuleDescriptor(rule =>
242-
rule
239+
.TagMatchingRuleDescriptor(rule => rule
243240
.RequireTagName("input")
244-
.RequireAttributeDescriptor(attribute =>
245-
attribute
246-
.Name("nodashprefix")
247-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch)))
241+
.RequireAttributeDescriptor(attribute => attribute
242+
.Name("nodashprefix", RequiredAttributeNameComparison.PrefixMatch)))
248243
.Build();
249244
var catchAllDescriptor = TagHelperDescriptorBuilder.Create("CatchAllTagHelper", "SomeAssembly")
250-
.TagMatchingRuleDescriptor(rule =>
251-
rule
245+
.TagMatchingRuleDescriptor(rule => rule
252246
.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName)
253247
.RequireAttributeDescriptor(attribute => attribute.Name("class")))
254248
.Build();
255249
var catchAllDescriptor2 = TagHelperDescriptorBuilder.Create("CatchAllTagHelper2", "SomeAssembly")
256-
.TagMatchingRuleDescriptor(rule =>
257-
rule
250+
.TagMatchingRuleDescriptor(rule => rule
258251
.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName)
259252
.RequireAttributeDescriptor(attribute => attribute.Name("custom"))
260253
.RequireAttributeDescriptor(attribute => attribute.Name("class")))
261254
.Build();
262255
var catchAllWildcardPrefixDescriptor = TagHelperDescriptorBuilder.Create("CatchAllWildCardAttribute", "SomeAssembly")
263-
.TagMatchingRuleDescriptor(rule =>
264-
rule
256+
.TagMatchingRuleDescriptor(rule => rule
265257
.RequireTagName(TagHelperMatchingConventions.ElementCatchAllName)
266-
.RequireAttributeDescriptor(attribute =>
267-
attribute
268-
.Name("prefix-")
269-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch)))
258+
.RequireAttributeDescriptor(attribute => attribute
259+
.Name("prefix-", RequiredAttributeNameComparison.PrefixMatch)))
270260
.Build();
271261
ImmutableArray<TagHelperDescriptor> defaultAvailableDescriptors =
272262
[divDescriptor, inputDescriptor, catchAllDescriptor, catchAllDescriptor2];

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TagHelperMatchingConventionsTest.cs

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,101 +31,79 @@ public static TheoryData RequiredAttributeDescriptorData
3131
false
3232
},
3333
{
34-
builder => builder
35-
.Name("route-")
36-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch),
34+
builder => builder.Name("route-", RequiredAttributeNameComparison.PrefixMatch),
3735
"ROUTE-area",
3836
"manage",
3937
true
4038
},
4139
{
42-
builder => builder
43-
.Name("route-")
44-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch),
40+
builder => builder.Name("route-", RequiredAttributeNameComparison.PrefixMatch),
4541
"routearea",
4642
"manage",
4743
false
4844
},
4945
{
50-
builder => builder
51-
.Name("route-")
52-
.NameComparison(RequiredAttributeNameComparison.PrefixMatch),
46+
builder => builder.Name("route-", RequiredAttributeNameComparison.PrefixMatch),
5347
"route-",
5448
"manage",
5549
false
5650
},
5751
{
58-
builder => builder
59-
.Name("key")
60-
.NameComparison(RequiredAttributeNameComparison.FullMatch),
52+
builder => builder.Name("key", RequiredAttributeNameComparison.FullMatch),
6153
"KeY",
6254
"value",
6355
true
6456
},
6557
{
66-
builder => builder
67-
.Name("key")
68-
.NameComparison(RequiredAttributeNameComparison.FullMatch),
58+
builder => builder.Name("key", RequiredAttributeNameComparison.FullMatch),
6959
"keys",
7060
"value",
7161
false
7262
},
7363
{
7464
builder => builder
75-
.Name("key")
76-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
77-
.Value("value")
78-
.ValueComparison(RequiredAttributeValueComparison.FullMatch),
65+
.Name("key", RequiredAttributeNameComparison.FullMatch)
66+
.Value("value", RequiredAttributeValueComparison.FullMatch),
7967
"key",
8068
"value",
8169
true
8270
},
8371
{
8472
builder => builder
85-
.Name("key")
86-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
87-
.Value("value")
88-
.ValueComparison(RequiredAttributeValueComparison.FullMatch),
73+
.Name("key", RequiredAttributeNameComparison.FullMatch)
74+
.Value("value", RequiredAttributeValueComparison.FullMatch),
8975
"key",
9076
"Value",
9177
false
9278
},
9379
{
9480
builder => builder
95-
.Name("class")
96-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
97-
.Value("btn")
98-
.ValueComparison(RequiredAttributeValueComparison.PrefixMatch),
81+
.Name("class", RequiredAttributeNameComparison.FullMatch)
82+
.Value("btn", RequiredAttributeValueComparison.PrefixMatch),
9983
"class",
10084
"btn btn-success",
10185
true
10286
},
10387
{
10488
builder => builder
105-
.Name("class")
106-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
107-
.Value("btn")
108-
.ValueComparison(RequiredAttributeValueComparison.PrefixMatch),
89+
.Name("class", RequiredAttributeNameComparison.FullMatch)
90+
.Value("btn", RequiredAttributeValueComparison.PrefixMatch),
10991
"class",
11092
"BTN btn-success",
11193
false
11294
},
11395
{
11496
builder => builder
115-
.Name("href")
116-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
117-
.Value("#navigate")
118-
.ValueComparison(RequiredAttributeValueComparison.SuffixMatch),
97+
.Name("href", RequiredAttributeNameComparison.FullMatch)
98+
.Value("#navigate", RequiredAttributeValueComparison.SuffixMatch),
11999
"href",
120100
"/home/index#navigate",
121101
true
122102
},
123103
{
124104
builder => builder
125-
.Name("href")
126-
.NameComparison(RequiredAttributeNameComparison.FullMatch)
127-
.Value("#navigate")
128-
.ValueComparison(RequiredAttributeValueComparison.SuffixMatch),
105+
.Name("href", RequiredAttributeNameComparison.FullMatch)
106+
.Value("#navigate", RequiredAttributeValueComparison.SuffixMatch),
129107
"href",
130108
"/home/index#NAVigate",
131109
false

0 commit comments

Comments
 (0)