diff --git a/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs b/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs index a1a1a8b408..2dcf943c4f 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Reflection; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.Extensions.WebEncoders; @@ -108,6 +107,16 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + IEnumerable attributeNames; if (ElementAttributeLookups.TryGetValue(output.TagName, out attributeNames)) { @@ -130,6 +139,16 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers /// The . protected void ProcessUrlAttribute(string attributeName, TagHelperOutput output) { + if (attributeName == null) + { + throw new ArgumentNullException(nameof(attributeName)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + IEnumerable attributes; if (output.Attributes.TryGetAttributes(attributeName, out attributes)) { diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs index 1d75b25bd9..0f007a2f48 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs @@ -111,6 +111,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + // If "href" is already set, it means the user is attempting to use a normal anchor. if (output.Attributes.ContainsName(Href)) { diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs index 84d8a56395..10bf6d3b10 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs @@ -138,6 +138,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + TagHelperContent result = null; if (Enabled) { diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/EnvironmentTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/EnvironmentTagHelper.cs index 8029209710..fc0eb0f175 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/EnvironmentTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/EnvironmentTagHelper.cs @@ -48,6 +48,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + // Always strip the outer tag name as we never want to render output.TagName = null; @@ -80,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Matching environment name found, do nothing return; } - + // No matching environment name found, suppress all output output.SuppressOutput(); } diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs index 0f08b1b6a3..7b75c89985 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs @@ -99,6 +99,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + var antiforgeryDefault = true; // If "action" is already set, it means the user is attempting to use a normal
. diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs index 0ead4fbdcd..74214024b9 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs @@ -1,10 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Mvc.Razor.TagHelpers; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.TagHelpers.Internal; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -87,6 +87,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + output.CopyHtmlAttribute(SrcAttributeName, context); ProcessUrlAttribute(SrcAttributeName, output); diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs index 4747348e25..481c6eab61 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs @@ -133,6 +133,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + // Pass through attributes that are also well-known HTML attributes. Must be done prior to any copying // from a TagBuilder. if (InputTypeName != null) diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/LabelTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/LabelTagHelper.cs index d6d7e4bbc7..0dfbcf9e8d 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/LabelTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/LabelTagHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewFeatures; @@ -50,6 +51,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// Does nothing if is null. public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + var tagBuilder = Generator.GenerateLabel( ViewContext, For.ModelExplorer, diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs index 26dee69edc..fbd1213b4b 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs @@ -8,7 +8,6 @@ using System.Linq; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Mvc.Razor.TagHelpers; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.TagHelpers.Internal; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -217,7 +216,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { - string resolvedUrl; + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } // Pass through attribute that is also a well-known HTML attribute. if (Href != null) @@ -274,6 +281,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers if (mode == Mode.Fallback) { + string resolvedUrl; if (TryResolveUrl(FallbackHref, encodeWebRoot: false, resolvedUrl: out resolvedUrl)) { FallbackHref = resolvedUrl; diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs index e6118e5330..c8abd8034f 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs @@ -61,6 +61,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + // Pass through attributes that are also well-known HTML attributes. if (Value != null) { diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs index 971e33ea70..98f7c96329 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs @@ -7,7 +7,6 @@ using System.Linq; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Mvc.Razor.TagHelpers; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.TagHelpers.Internal; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -185,7 +184,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { - string resolvedUrl; + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } // Pass through attribute that is also a well-known HTML attribute. if (Src != null) @@ -242,6 +249,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers if (mode == Mode.Fallback) { + string resolvedUrl; if (TryResolveUrl(FallbackSrc, encodeWebRoot: false, resolvedUrl: out resolvedUrl)) { FallbackSrc = resolvedUrl; diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs index 48ab9263ca..2cd87bbe9b 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/SelectTagHelper.cs @@ -76,6 +76,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + // Note null or empty For.Name is allowed because TemplateInfo.HtmlFieldPrefix may be sufficient. // IHtmlGenerator will enforce name requirements. var metadata = For.Metadata; diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/TextAreaTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/TextAreaTagHelper.cs index 19f771aa12..8ea9cfab93 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/TextAreaTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/TextAreaTagHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -49,6 +50,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// Does nothing if is null. public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + var tagBuilder = Generator.GenerateTextArea( ViewContext, For.ModelExplorer, diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs index 7733c824f9..ef375eb48d 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationMessageTagHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.ViewFeatures; @@ -51,6 +52,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// Does nothing if is null. public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + if (For != null) { var tagBuilder = Generator.GenerateValidationMessage(ViewContext, diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationSummaryTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationSummaryTagHelper.cs index 796222b6b7..312216d63d 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationSummaryTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ValidationSummaryTagHelper.cs @@ -83,6 +83,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers /// Does nothing if is . public override void Process(TagHelperContext context, TagHelperOutput output) { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (output == null) + { + throw new ArgumentNullException(nameof(output)); + } + if (ValidationSummary == ValidationSummary.None) { return; diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/TagHelpers/UrlResolutionTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/TagHelpers/UrlResolutionTagHelperTest.cs index 3c0f95e48a..1ce88fa072 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/TagHelpers/UrlResolutionTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/TagHelpers/UrlResolutionTagHelperTest.cs @@ -2,9 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; +using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; -using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.Extensions.WebEncoders; using Moq; @@ -57,8 +59,15 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers .Returns(new Func(value => "/approot" + value.Substring(1))); var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, new TestHtmlEncoder()); + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act - tagHelper.Process(context: null, output: tagHelperOutput); + tagHelper.Process(context, tagHelperOutput); // Assert var attribute = Assert.Single(tagHelperOutput.Attributes); @@ -106,8 +115,15 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers .Returns("approot/home/index.html"); var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null); + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act - tagHelper.Process(context: null, output: tagHelperOutput); + tagHelper.Process(context, tagHelperOutput); // Assert var attribute = Assert.Single(tagHelperOutput.Attributes); @@ -128,8 +144,15 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers }); var tagHelper = new UrlResolutionTagHelper(urlHelper: null, htmlEncoder: null); + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act - tagHelper.Process(context: null, output: tagHelperOutput); + tagHelper.Process(context, tagHelperOutput); // Assert var attribute = Assert.Single(tagHelperOutput.Attributes); @@ -162,9 +185,16 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers .Returns("UnexpectedResult"); var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null); + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act & Assert var exception = Assert.Throws( - () => tagHelper.Process(context: null, output: tagHelperOutput)); + () => tagHelper.Process(context, tagHelperOutput)); Assert.Equal(expectedExceptionMessage, exception.Message, StringComparer.Ordinal); } } diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs index 5ba2429e9e..4abc938f60 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs @@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.Extensions.WebEncoders.Testing; using Moq; using Xunit; @@ -220,9 +219,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers "'asp-action', 'asp-controller', 'asp-route', 'asp-protocol', 'asp-host', or " + "'asp-fragment' attribute."; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act & Assert var ex = await Assert.ThrowsAsync( - () => anchorTagHelper.ProcessAsync(context: null, output: output)); + () => anchorTagHelper.ProcessAsync(context, output)); Assert.Equal(expectedErrorMessage, ex.Message); } @@ -248,9 +254,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedErrorMessage = "Cannot determine an 'href' attribute for . An with a specified " + "'asp-route' must not have an 'asp-action' or 'asp-controller' attribute."; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act & Assert var ex = await Assert.ThrowsAsync( - () => anchorTagHelper.ProcessAsync(context: null, output: output)); + () => anchorTagHelper.ProcessAsync(context, output)); Assert.Equal(expectedErrorMessage, ex.Message); } diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs index 99c9c4f826..3fb18c4859 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs @@ -407,9 +407,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers "'action' must not have attributes starting with 'asp-route-' or an " + "'asp-action' or 'asp-controller' or 'asp-route' attribute."; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act & Assert var ex = await Assert.ThrowsAsync( - () => formTagHelper.ProcessAsync(context: null, output: tagHelperOutput)); + () => formTagHelper.ProcessAsync(context, tagHelperOutput)); Assert.Equal(expectedErrorMessage, ex.Message); } @@ -431,9 +438,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedErrorMessage = "Cannot determine an 'action' attribute for . A with a specified " + "'asp-route' must not have an 'asp-action' or 'asp-controller' attribute."; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act & Assert var ex = await Assert.ThrowsAsync( - () => formTagHelper.ProcessAsync(context: null, output: output)); + () => formTagHelper.ProcessAsync(context, output)); Assert.Equal(expectedErrorMessage, ex.Message); } diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs index ca2aec784d..d02ce3c045 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); - + var viewContext = TestableHtmlGenerator.GetViewContext(model: null, htmlGenerator: htmlGenerator, metadataProvider: metadataProvider); @@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers validationMessageTagHelper.ViewContext = expectedViewContext; // Act & Assert - await validationMessageTagHelper.ProcessAsync(context, output: output); + await validationMessageTagHelper.ProcessAsync(context, output); generator.Verify(); Assert.Equal("span", output.TagName); @@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers validationMessageTagHelper.ViewContext = viewContext; // Act - await validationMessageTagHelper.ProcessAsync(context, output: output); + await validationMessageTagHelper.ProcessAsync(context, output); // Assert Assert.Equal("span", output.TagName); @@ -243,7 +243,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers validationMessageTagHelper.ViewContext = viewContext; // Act - await validationMessageTagHelper.ProcessAsync(context, output: output); + await validationMessageTagHelper.ProcessAsync(context, output); // Assert Assert.Equal("span", output.TagName); @@ -271,11 +271,18 @@ namespace Microsoft.AspNet.Mvc.TagHelpers output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + var viewContext = CreateViewContext(); validationMessageTagHelper.ViewContext = viewContext; // Act - await validationMessageTagHelper.ProcessAsync(context: null, output: output); + await validationMessageTagHelper.ProcessAsync(context, output); // Assert Assert.Equal("span", output.TagName); diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs index e618b2c91f..e228a40976 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs @@ -115,11 +115,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); - validationSummaryTagHelper.ViewContext = expectedViewContext; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act & Assert - await validationSummaryTagHelper.ProcessAsync(context: null, output: output); + await validationSummaryTagHelper.ProcessAsync(context, output); generator.Verify(); Assert.Equal("div", output.TagName); @@ -166,8 +172,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var viewContext = CreateViewContext(); validationSummaryTagHelper.ViewContext = viewContext; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act - await validationSummaryTagHelper.ProcessAsync(context: null, output: output); + await validationSummaryTagHelper.ProcessAsync(context, output); // Assert Assert.Equal("div", output.TagName); @@ -207,8 +220,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var viewContext = CreateViewContext(); validationSummaryTagHelper.ViewContext = viewContext; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act - await validationSummaryTagHelper.ProcessAsync(context: null, output: output); + await validationSummaryTagHelper.ProcessAsync(context, output); // Assert Assert.Equal("div", output.TagName); @@ -255,8 +275,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var viewContext = CreateViewContext(); validationSummaryTagHelper.ViewContext = viewContext; + var context = new TagHelperContext( + allAttributes: new ReadOnlyTagHelperAttributeList( + Enumerable.Empty()), + items: new Dictionary(), + uniqueId: "test", + getChildContentAsync: _ => Task.FromResult(null)); + // Act - await validationSummaryTagHelper.ProcessAsync(context: null, output: output); + await validationSummaryTagHelper.ProcessAsync(context, output); // Assert Assert.Equal("div", output.TagName);