Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 02695f5

Browse files
author
NTaylorMullen
committed
Addressed code review comments.
1 parent fcc8b44 commit 02695f5

9 files changed

+95
-80
lines changed

src/Microsoft.AspNet.Mvc.TagHelpers/LabelTagHelper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNet.Mvc.Rendering;
66
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
7-
using Microsoft.AspNet.Razor.TagHelpers;
87

98
namespace Microsoft.AspNet.Mvc.TagHelpers
109
{
@@ -50,16 +49,17 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5049
// We check for whitespace to detect scenarios such as:
5150
// <label for="Name">
5251
// </label>
53-
if (string.IsNullOrWhiteSpace(childContent))
52+
if (string.IsNullOrEmpty(output.Content))
5453
{
55-
if (string.IsNullOrEmpty(output.Content))
54+
if (string.IsNullOrWhiteSpace(childContent))
5655
{
56+
// Provide default label text since there was nothing useful in the Razor source.
5757
output.Content = tagBuilder.InnerHtml;
5858
}
59-
}
60-
else if (string.IsNullOrEmpty(output.Content))
61-
{
62-
output.Content = childContent;
59+
else
60+
{
61+
output.Content = childContent;
62+
}
6363
}
6464
}
6565
}

src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNet.Mvc.Rendering;
66
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
7-
using Microsoft.AspNet.Razor.TagHelpers;
87

98
namespace Microsoft.AspNet.Mvc.TagHelpers
109
{
@@ -52,16 +51,17 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5251
// We check for whitespace to detect scenarios such as:
5352
// <span validation-for="Name">
5453
// </span>
55-
if (string.IsNullOrWhiteSpace(childContent))
54+
if (string.IsNullOrEmpty(output.Content))
5655
{
57-
if (string.IsNullOrWhiteSpace(output.Content))
56+
if (string.IsNullOrWhiteSpace(childContent))
5857
{
58+
// Provide default label text since there was nothing useful in the Razor source.
5959
output.Content = tagBuilder.InnerHtml;
6060
}
61-
}
62-
else if (string.IsNullOrEmpty(output.Content))
63-
{
64-
output.Content = childContent;
61+
else
62+
{
63+
output.Content = childContent;
64+
}
6565
}
6666
}
6767
}

test/Microsoft.AspNet.Mvc.TagHelpers.Test/InputTagHelperTest.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ public async Task TagHelper_RestoresTypeAndValue_IfForNotBound()
571571
var expectedPostContent = "original post-content";
572572
var expectedTagName = "input";
573573

574-
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
575-
uniqueId: "test",
576-
getChildContentAsync: () => Task.FromResult("Something"));
574+
var tagHelperContext = new TagHelperContext(
575+
allAttributes: new Dictionary<string, object>(),
576+
uniqueId: "test",
577+
getChildContentAsync: () => Task.FromResult("Something"));
577578
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
578579
{
579580
PreContent = expectedPreContent,
@@ -593,7 +594,7 @@ public async Task TagHelper_RestoresTypeAndValue_IfForNotBound()
593594
tagHelper.For = null;
594595

595596
// Act
596-
await tagHelper.ProcessAsync(context, output);
597+
await tagHelper.ProcessAsync(tagHelperContext, output);
597598

598599
// Assert
599600
Assert.Equal(expectedAttributes, output.Attributes);
@@ -625,7 +626,7 @@ public async Task ProcessAsync_Throws_IfForNotBoundButFormatIs()
625626
var expectedMessage = "Unable to format without a 'asp-for' expression for <input>. 'asp-format' must " +
626627
"be null if 'asp-for' is null.";
627628

628-
var context = new TagHelperContext(
629+
var tagHelperContext = new TagHelperContext(
629630
allAttributes: new Dictionary<string, object>(),
630631
uniqueId: "test",
631632
getChildContentAsync: () => Task.FromResult("Something"));
@@ -637,7 +638,7 @@ public async Task ProcessAsync_Throws_IfForNotBoundButFormatIs()
637638

638639
// Act & Assert
639640
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
640-
() => tagHelper.ProcessAsync(context, output));
641+
() => tagHelper.ProcessAsync(tagHelperContext, output));
641642
Assert.Equal(expectedMessage, exception.Message);
642643
}
643644

test/Microsoft.AspNet.Mvc.TagHelpers.Test/LabelTagHelperTest.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput(
165165
var expectedPreContent = "original pre-content";
166166
var expectedPostContent = "original post-content";
167167

168-
var context = new TagHelperContext(
168+
var tagHelperContext = new TagHelperContext(
169169
allAttributes: new Dictionary<string, object>(),
170170
uniqueId: "test",
171171
getChildContentAsync: () => Task.FromResult(tagHelperOutputContent.OriginalChildContent));
@@ -185,7 +185,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput(
185185
tagHelper.Generator = htmlGenerator;
186186

187187
// Act
188-
await tagHelper.ProcessAsync(context, output);
188+
await tagHelper.ProcessAsync(tagHelperContext, output);
189189

190190
// Assert
191191
Assert.Equal(expectedAttributes, output.Attributes);
@@ -217,9 +217,10 @@ public async Task TagHelper_LeavesOutputUnchanged_IfForNotBound2()
217217
var modelExpression = new ModelExpression(nameof(Model.Text), metadata);
218218
var tagHelper = new LabelTagHelper();
219219

220-
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
221-
uniqueId: "test",
222-
getChildContentAsync: () => Task.FromResult("Something"));
220+
var tagHelperContext = new TagHelperContext(
221+
allAttributes: new Dictionary<string, object>(),
222+
uniqueId: "test",
223+
getChildContentAsync: () => Task.FromResult("Something"));
223224
var output = new TagHelperOutput(expectedTagName, expectedAttributes)
224225
{
225226
PreContent = expectedPreContent,
@@ -234,7 +235,7 @@ public async Task TagHelper_LeavesOutputUnchanged_IfForNotBound2()
234235
tagHelper.Generator = htmlGenerator;
235236

236237
// Act
237-
await tagHelper.ProcessAsync(context, output);
238+
await tagHelper.ProcessAsync(tagHelperContext, output);
238239

239240
// Assert
240241
Assert.Equal(expectedAttributes, output.Attributes);

test/Microsoft.AspNet.Mvc.TagHelpers.Test/OptionTagHelperTest.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ public async Task ProcessAsync_GeneratesExpectedOutput(
136136
{ "selected", selected },
137137
{ "value", value },
138138
};
139-
var context = new TagHelperContext(contextAttributes,
140-
uniqueId: "test",
141-
getChildContentAsync: () => Task.FromResult(originalContent));
139+
var tagHelperContext = new TagHelperContext(
140+
contextAttributes,
141+
uniqueId: "test",
142+
getChildContentAsync: () => Task.FromResult(originalContent));
142143
var output = new TagHelperOutput(expectedTagName, originalAttributes)
143144
{
144145
Content = originalContent,
@@ -161,7 +162,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput(
161162
};
162163

163164
// Act
164-
await tagHelper.ProcessAsync(context, output);
165+
await tagHelper.ProcessAsync(tagHelperContext, output);
165166

166167
// Assert
167168
Assert.Equal(
@@ -193,9 +194,10 @@ public async Task ProcessAsync_DoesNotUseGenerator_IfSelectedNullOrNoSelectedVal
193194
};
194195
var originalPreContent = "original pre-content";
195196
var originalPostContent = "original post-content";
196-
var context = new TagHelperContext(contextAttributes,
197-
uniqueId: "test",
198-
getChildContentAsync: () => Task.FromResult(originalContent));
197+
var tagHelperContext = new TagHelperContext(
198+
contextAttributes,
199+
uniqueId: "test",
200+
getChildContentAsync: () => Task.FromResult(originalContent));
199201
var output = new TagHelperOutput(originalTagName, originalAttributes)
200202
{
201203
PreContent = originalPreContent,
@@ -220,7 +222,7 @@ public async Task ProcessAsync_DoesNotUseGenerator_IfSelectedNullOrNoSelectedVal
220222

221223
// Act & Assert (does not throw)
222224
// Tag helper would throw an NRE if it used Generator value.
223-
await tagHelper.ProcessAsync(context, output);
225+
await tagHelper.ProcessAsync(tagHelperContext, output);
224226
}
225227

226228
[Theory]
@@ -247,9 +249,10 @@ public async Task ProcessAsync_DoesNotUseViewContext_IfSelectedNotNull(
247249
};
248250
var originalPreContent = "original pre-content";
249251
var originalPostContent = "original post-content";
250-
var context = new TagHelperContext(contextAttributes,
251-
uniqueId: "test",
252-
getChildContentAsync: () => Task.FromResult(originalContent));
252+
var tagHelperContext = new TagHelperContext(
253+
contextAttributes,
254+
uniqueId: "test",
255+
getChildContentAsync: () => Task.FromResult(originalContent));
253256
var output = new TagHelperOutput(originalTagName, originalAttributes)
254257
{
255258
PreContent = originalPreContent,
@@ -266,7 +269,7 @@ public async Task ProcessAsync_DoesNotUseViewContext_IfSelectedNotNull(
266269

267270
// Act & Assert (does not throw)
268271
// Tag helper would throw an NRE if it used ViewContext or Generator values.
269-
await tagHelper.ProcessAsync(context, output);
272+
await tagHelper.ProcessAsync(tagHelperContext, output);
270273
}
271274
}
272275
}

test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ public async Task ProcessAsync_GeneratesExpectedOutput(
184184
var metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName: "Text");
185185
var modelExpression = new ModelExpression(nameAndId.Name, metadata);
186186

187-
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
188-
uniqueId: "test",
189-
getChildContentAsync: () => Task.FromResult("Something"));
187+
var tagHelperContext = new TagHelperContext(
188+
allAttributes: new Dictionary<string, object>(),
189+
uniqueId: "test",
190+
getChildContentAsync: () => Task.FromResult("Something"));
190191
var output = new TagHelperOutput(expectedTagName, originalAttributes)
191192
{
192193
PreContent = expectedPreContent,
@@ -211,7 +212,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput(
211212
};
212213

213214
// Act
214-
await tagHelper.ProcessAsync(context, output);
215+
await tagHelper.ProcessAsync(tagHelperContext, output);
215216

216217
// Assert
217218
Assert.Equal(expectedAttributes, output.Attributes);
@@ -263,9 +264,10 @@ public async Task ProcessAsync_GeneratesExpectedOutput_WithItems(
263264
var metadata = metadataProvider.GetMetadataForProperty(modelAccessor, containerType, propertyName: "Text");
264265
var modelExpression = new ModelExpression(nameAndId.Name, metadata);
265266

266-
var context = new TagHelperContext(allAttributes: new Dictionary<string, object>(),
267-
uniqueId: "test",
268-
getChildContentAsync: () => Task.FromResult("Something"));
267+
var tagHelperContext = new TagHelperContext(
268+
allAttributes: new Dictionary<string, object>(),
269+
uniqueId: "test",
270+
getChildContentAsync: () => Task.FromResult("Something"));
269271
var output = new TagHelperOutput(expectedTagName, originalAttributes)
270272
{
271273
PreContent = expectedPreContent,
@@ -292,7 +294,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput_WithItems(
292294
};
293295

294296
// Act
295-
await tagHelper.ProcessAsync(context, output);
297+
await tagHelper.ProcessAsync(tagHelperContext, output);
296298

297299
// Assert
298300
Assert.Equal(expectedAttributes, output.Attributes);
@@ -329,9 +331,10 @@ public async Task ProcessAsync_CallsGeneratorWithExpectedValues_ItemsAndMultiple
329331
var propertyName = "Property1";
330332
var expectedTagName = "select";
331333

332-
var context = new TagHelperContext(contextAttributes,
333-
uniqueId: "test",
334-
getChildContentAsync: () => Task.FromResult("Something"));
334+
var tagHelperContext = new TagHelperContext(
335+
contextAttributes,
336+
uniqueId: "test",
337+
getChildContentAsync: () => Task.FromResult("Something"));
335338
var output = new TagHelperOutput(expectedTagName, originalAttributes);
336339

337340
// TODO: https://github.com/aspnet/Mvc/issues/1253
@@ -369,7 +372,7 @@ public async Task ProcessAsync_CallsGeneratorWithExpectedValues_ItemsAndMultiple
369372
};
370373

371374
// Act
372-
await tagHelper.ProcessAsync(context, output);
375+
await tagHelper.ProcessAsync(tagHelperContext, output);
373376

374377
// Assert
375378
htmlGenerator.Verify();
@@ -394,9 +397,10 @@ public async Task TagHelper_CallsGeneratorWithExpectedValues_RealModelType(
394397
var propertyName = "Property1";
395398
var tagName = "select";
396399

397-
var context = new TagHelperContext(contextAttributes,
398-
uniqueId: "test",
399-
getChildContentAsync: () => Task.FromResult("Something"));
400+
var tagHelperContext = new TagHelperContext(
401+
contextAttributes,
402+
uniqueId: "test",
403+
getChildContentAsync: () => Task.FromResult("Something"));
400404
var output = new TagHelperOutput(tagName, originalAttributes);
401405

402406
var metadataProvider = new EmptyModelMetadataProvider();
@@ -427,7 +431,7 @@ public async Task TagHelper_CallsGeneratorWithExpectedValues_RealModelType(
427431
};
428432

429433
// Act
430-
await tagHelper.ProcessAsync(context, output);
434+
await tagHelper.ProcessAsync(tagHelperContext, output);
431435

432436
// Assert
433437
htmlGenerator.Verify();
@@ -462,9 +466,10 @@ public async Task ProcessAsync_RestoresMultiple_IfForNotBound(string attributeNa
462466
var expectedPostContent = "original post-content";
463467
var expectedTagName = "select";
464468

465-
var context = new TagHelperContext(contextAttributes,
466-
uniqueId: "test",
467-
getChildContentAsync: () => Task.FromResult("Something"));
469+
var tagHelperContext = new TagHelperContext(
470+
contextAttributes,
471+
uniqueId: "test",
472+
getChildContentAsync: () => Task.FromResult("Something"));
468473
var output = new TagHelperOutput(expectedTagName, originalAttributes)
469474
{
470475
PreContent = expectedPreContent,
@@ -479,7 +484,7 @@ public async Task ProcessAsync_RestoresMultiple_IfForNotBound(string attributeNa
479484
};
480485

481486
// Act
482-
await tagHelper.ProcessAsync(context, output);
487+
await tagHelper.ProcessAsync(tagHelperContext, output);
483488

484489
// Assert
485490
Assert.Equal(expectedAttributes, output.Attributes);
@@ -499,9 +504,10 @@ public async Task ProcessAsync_Throws_IfForNotBoundButItemsIs()
499504
var expectedTagName = "select";
500505
var expectedMessage = "Cannot determine body for <select>. 'asp-items' must be null if 'asp-for' is null.";
501506

502-
var context = new TagHelperContext(contextAttributes,
503-
uniqueId: "test",
504-
getChildContentAsync: () => Task.FromResult("Something"));
507+
var tagHelperContext = new TagHelperContext(
508+
contextAttributes,
509+
uniqueId: "test",
510+
getChildContentAsync: () => Task.FromResult("Something"));
505511
var output = new TagHelperOutput(expectedTagName, originalAttributes);
506512
var tagHelper = new SelectTagHelper
507513
{
@@ -510,7 +516,7 @@ public async Task ProcessAsync_Throws_IfForNotBoundButItemsIs()
510516

511517
// Act & Assert
512518
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
513-
() => tagHelper.ProcessAsync(context, output));
519+
() => tagHelper.ProcessAsync(tagHelperContext, output));
514520
Assert.Equal(expectedMessage, exception.Message);
515521
}
516522

@@ -531,9 +537,10 @@ public async Task ProcessAsync_Throws_IfMultipleInvalid(string multiple)
531537
var expectedMessage = "Cannot parse 'multiple' value '" + multiple +
532538
"' for <select>. Acceptable values are 'false', 'true' and 'multiple'.";
533539

534-
var context = new TagHelperContext(contextAttributes,
535-
uniqueId: "test",
536-
getChildContentAsync: () => Task.FromResult("Something"));
540+
var tagHelperContext = new TagHelperContext(
541+
contextAttributes,
542+
uniqueId: "test",
543+
getChildContentAsync: () => Task.FromResult("Something"));
537544
var output = new TagHelperOutput(expectedTagName, originalAttributes);
538545

539546
var metadataProvider = new EmptyModelMetadataProvider();
@@ -549,7 +556,7 @@ public async Task ProcessAsync_Throws_IfMultipleInvalid(string multiple)
549556

550557
// Act & Assert
551558
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
552-
() => tagHelper.ProcessAsync(context, output));
559+
() => tagHelper.ProcessAsync(tagHelperContext, output));
553560
Assert.Equal(expectedMessage, exception.Message);
554561
}
555562

0 commit comments

Comments
 (0)