@@ -33,15 +33,18 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
3333 { "method" , "post" } ,
3434 { "asp-anti-forgery" , true }
3535 } ,
36- uniqueId : "test" ) ;
36+ uniqueId : "test" ,
37+ getChildContentAsync : ( ) => Task . FromResult ( "Something Else" ) ) ;
3738 var output = new TagHelperOutput (
3839 expectedTagName ,
3940 attributes : new Dictionary < string , string >
4041 {
4142 { "id" , "myform" } ,
4243 { "asp-route-foo" , "bar" } ,
43- } ,
44- content : "Something" ) ;
44+ } )
45+ {
46+ PostContent = "Something"
47+ } ;
4548 var urlHelper = new Mock < IUrlHelper > ( ) ;
4649 urlHelper
4750 . Setup ( mock => mock . Action ( It . IsAny < string > ( ) ,
@@ -56,8 +59,8 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
5659 var viewContext = TestableHtmlGenerator . GetViewContext ( model : null ,
5760 htmlGenerator : htmlGenerator ,
5861 metadataProvider : metadataProvider ) ;
59- var expectedContent = "Something" + htmlGenerator . GenerateAntiForgery ( viewContext )
60- . ToString ( TagRenderMode . SelfClosing ) ;
62+ var expectedPostContent = "Something" + htmlGenerator . GenerateAntiForgery ( viewContext )
63+ . ToString ( TagRenderMode . SelfClosing ) ;
6164 var formTagHelper = new FormTagHelper
6265 {
6366 Action = "index" ,
@@ -79,24 +82,27 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
7982 Assert . Equal ( "post" , attribute . Value ) ;
8083 attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "action" ) ) ;
8184 Assert . Equal ( "home/index" , attribute . Value ) ;
82- Assert . Equal ( expectedContent , output . Content ) ;
85+ Assert . Empty ( output . PreContent ) ;
86+ Assert . Empty ( output . Content ) ;
87+ Assert . Equal ( expectedPostContent , output . PostContent ) ;
8388 Assert . Equal ( expectedTagName , output . TagName ) ;
8489 }
8590
8691 [ Theory ]
8792 [ InlineData ( true , "<input />" ) ]
8893 [ InlineData ( false , "" ) ]
8994 [ InlineData ( null , "<input />" ) ]
90- public async Task ProcessAsync_GeneratesAntiForgeryCorrectly ( bool ? antiForgery , string expectedContent )
95+ public async Task ProcessAsync_GeneratesAntiForgeryCorrectly ( bool ? antiForgery , string expectedPostContent )
9196 {
9297 // Arrange
9398 var viewContext = CreateViewContext ( ) ;
9499 var context = new TagHelperContext (
95- allAttributes : new Dictionary < string , object > ( ) , uniqueId : "test" ) ;
100+ allAttributes : new Dictionary < string , object > ( ) ,
101+ uniqueId : "test" ,
102+ getChildContentAsync : ( ) => Task . FromResult ( "Something" ) ) ;
96103 var output = new TagHelperOutput (
97104 "form" ,
98- attributes : new Dictionary < string , string > ( ) ,
99- content : string . Empty ) ;
105+ attributes : new Dictionary < string , string > ( ) ) ;
100106 var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
101107 generator
102108 . Setup ( mock => mock . GenerateForm (
@@ -124,7 +130,9 @@ public async Task ProcessAsync_GeneratesAntiForgeryCorrectly(bool? antiForgery,
124130 // Assert
125131 Assert . Equal ( "form" , output . TagName ) ;
126132 Assert . Empty ( output . Attributes ) ;
127- Assert . Equal ( expectedContent , output . Content ) ;
133+ Assert . Empty ( output . PreContent ) ;
134+ Assert . Empty ( output . Content ) ;
135+ Assert . Equal ( expectedPostContent , output . PostContent ) ;
128136 }
129137
130138 [ Fact ]
@@ -133,16 +141,17 @@ public async Task ProcessAsync_BindsRouteValuesFromTagHelperOutput()
133141 // Arrange
134142 var testViewContext = CreateViewContext ( ) ;
135143 var context = new TagHelperContext (
136- allAttributes : new Dictionary < string , object > ( ) , uniqueId : "test" ) ;
144+ allAttributes : new Dictionary < string , object > ( ) ,
145+ uniqueId : "test" ,
146+ getChildContentAsync : ( ) => Task . FromResult ( "Something" ) ) ;
137147 var expectedAttribute = new KeyValuePair < string , string > ( "asp-ROUTEE-NotRoute" , "something" ) ;
138148 var output = new TagHelperOutput (
139149 "form" ,
140150 attributes : new Dictionary < string , string > ( )
141151 {
142152 { "asp-route-val" , "hello" } ,
143153 { "asp-roUte--Foo" , "bar" }
144- } ,
145- content : string . Empty ) ;
154+ } ) ;
146155 output . Attributes . Add ( expectedAttribute ) ;
147156
148157 var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
@@ -184,7 +193,9 @@ public async Task ProcessAsync_BindsRouteValuesFromTagHelperOutput()
184193 Assert . Equal ( "form" , output . TagName ) ;
185194 var attribute = Assert . Single ( output . Attributes ) ;
186195 Assert . Equal ( expectedAttribute , attribute ) ;
196+ Assert . Empty ( output . PreContent ) ;
187197 Assert . Empty ( output . Content ) ;
198+ Assert . Empty ( output . PostContent ) ;
188199 generator . Verify ( ) ;
189200 }
190201
@@ -194,11 +205,12 @@ public async Task ProcessAsync_CallsIntoGenerateFormWithExpectedParameters()
194205 // Arrange
195206 var viewContext = CreateViewContext ( ) ;
196207 var context = new TagHelperContext (
197- allAttributes : new Dictionary < string , object > ( ) , uniqueId : "test" ) ;
208+ allAttributes : new Dictionary < string , object > ( ) ,
209+ uniqueId : "test" ,
210+ getChildContentAsync : ( ) => Task . FromResult ( "Something" ) ) ;
198211 var output = new TagHelperOutput (
199212 "form" ,
200- attributes : new Dictionary < string , string > ( ) ,
201- content : string . Empty ) ;
213+ attributes : new Dictionary < string , string > ( ) ) ;
202214 var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
203215 generator
204216 . Setup ( mock => mock . GenerateForm ( viewContext , "Index" , "Home" , null , "POST" , null ) )
@@ -220,7 +232,9 @@ public async Task ProcessAsync_CallsIntoGenerateFormWithExpectedParameters()
220232
221233 Assert . Equal ( "form" , output . TagName ) ;
222234 Assert . Empty ( output . Attributes ) ;
235+ Assert . Empty ( output . PreContent ) ;
223236 Assert . Empty ( output . Content ) ;
237+ Assert . Empty ( output . PostContent ) ;
224238 }
225239
226240 [ Theory ]
@@ -238,14 +252,15 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsSpecified(string
238252 attributes : new Dictionary < string , string >
239253 {
240254 { "aCTiON" , htmlAction } ,
241- } ,
242- content : string . Empty ) ;
255+ } ) ;
256+
243257 var context = new TagHelperContext (
244258 allAttributes : new Dictionary < string , object > ( )
245259 {
246260 { "METhod" , "POST" }
247261 } ,
248- uniqueId : "test" ) ;
262+ uniqueId : "test" ,
263+ getChildContentAsync : ( ) => Task . FromResult ( "Something" ) ) ;
249264
250265 // Act
251266 await formTagHelper . ProcessAsync ( context , output ) ;
@@ -257,7 +272,9 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsSpecified(string
257272 Assert . Equal ( htmlAction , attribute . Value ) ;
258273 attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "METhod" ) ) ;
259274 Assert . Equal ( "POST" , attribute . Value ) ;
275+ Assert . Empty ( output . PreContent ) ;
260276 Assert . Empty ( output . Content ) ;
277+ Assert . Empty ( output . PostContent ) ;
261278 }
262279
263280 [ Theory ]
@@ -266,11 +283,12 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsSpecified(string
266283 [ InlineData ( null , "" ) ]
267284 public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified (
268285 bool ? antiForgery ,
269- string expectedContent )
286+ string expectedPostContent )
270287 {
271288 // Arrange
272289 var viewContext = CreateViewContext ( ) ;
273290 var generator = new Mock < IHtmlGenerator > ( ) ;
291+
274292 generator . Setup ( mock => mock . GenerateAntiForgery ( It . IsAny < ViewContext > ( ) ) )
275293 . Returns ( new TagBuilder ( "input" ) ) ;
276294 var formTagHelper = new FormTagHelper
@@ -284,9 +302,15 @@ public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified(
284302 attributes : new Dictionary < string , string >
285303 {
286304 { "aCTiON" , "my-action" } ,
287- } ,
288- content : string . Empty ) ;
289- var context = new TagHelperContext ( allAttributes : new Dictionary < string , object > ( ) , uniqueId : "test" ) ;
305+ } ) ;
306+ var context = new TagHelperContext (
307+ allAttributes : new Dictionary < string , object > ( )
308+ {
309+ { "aCTiON" , "http://www.contoso.com" }
310+ } ,
311+ uniqueId : "test" ,
312+ getChildContentAsync : ( ) => Task . FromResult ( "Something" ) ) ;
313+
290314
291315 // Act
292316 await formTagHelper . ProcessAsync ( context , output ) ;
@@ -295,7 +319,9 @@ public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified(
295319 Assert . Equal ( "form" , output . TagName ) ;
296320 var attribute = Assert . Single ( output . Attributes ) ;
297321 Assert . Equal ( new KeyValuePair < string , string > ( "aCTiON" , "my-action" ) , attribute ) ;
298- Assert . Equal ( expectedContent , output . Content ) ;
322+ Assert . Empty ( output . PreContent ) ;
323+ Assert . Empty ( output . Content ) ;
324+ Assert . Equal ( expectedPostContent , output . PostContent ) ;
299325 }
300326
301327 [ Theory ]
@@ -314,8 +340,7 @@ public async Task ProcessAsync_ThrowsIfActionConflictsWithBoundAttributes(string
314340 attributes : new Dictionary < string , string >
315341 {
316342 { "action" , "my-action" } ,
317- } ,
318- content : string . Empty ) ;
343+ } ) ;
319344 if ( propertyName == "asp-route-" )
320345 {
321346 tagHelperOutput . Attributes . Add ( "asp-route-foo" , "bar" ) ;
0 commit comments