@@ -33,15 +33,18 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
33
33
{ "method" , "post" } ,
34
34
{ "asp-anti-forgery" , true }
35
35
} ,
36
- uniqueId : "test" ) ;
36
+ uniqueId : "test" ,
37
+ getChildContentAsync : ( ) => Task . FromResult ( "Something Else" ) ) ;
37
38
var output = new TagHelperOutput (
38
39
expectedTagName ,
39
40
attributes : new Dictionary < string , string >
40
41
{
41
42
{ "id" , "myform" } ,
42
43
{ "asp-route-foo" , "bar" } ,
43
- } ,
44
- content : "Something" ) ;
44
+ } )
45
+ {
46
+ PostContent = "Something"
47
+ } ;
45
48
var urlHelper = new Mock < IUrlHelper > ( ) ;
46
49
urlHelper
47
50
. Setup ( mock => mock . Action ( It . IsAny < string > ( ) ,
@@ -56,8 +59,8 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
56
59
var viewContext = TestableHtmlGenerator . GetViewContext ( model : null ,
57
60
htmlGenerator : htmlGenerator ,
58
61
metadataProvider : metadataProvider ) ;
59
- var expectedContent = "Something" + htmlGenerator . GenerateAntiForgery ( viewContext )
60
- . ToString ( TagRenderMode . SelfClosing ) ;
62
+ var expectedPostContent = "Something" + htmlGenerator . GenerateAntiForgery ( viewContext )
63
+ . ToString ( TagRenderMode . SelfClosing ) ;
61
64
var formTagHelper = new FormTagHelper
62
65
{
63
66
Action = "index" ,
@@ -79,24 +82,27 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
79
82
Assert . Equal ( "post" , attribute . Value ) ;
80
83
attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "action" ) ) ;
81
84
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 ) ;
83
88
Assert . Equal ( expectedTagName , output . TagName ) ;
84
89
}
85
90
86
91
[ Theory ]
87
92
[ InlineData ( true , "<input />" ) ]
88
93
[ InlineData ( false , "" ) ]
89
94
[ InlineData ( null , "<input />" ) ]
90
- public async Task ProcessAsync_GeneratesAntiForgeryCorrectly ( bool ? antiForgery , string expectedContent )
95
+ public async Task ProcessAsync_GeneratesAntiForgeryCorrectly ( bool ? antiForgery , string expectedPostContent )
91
96
{
92
97
// Arrange
93
98
var viewContext = CreateViewContext ( ) ;
94
99
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" ) ) ;
96
103
var output = new TagHelperOutput (
97
104
"form" ,
98
- attributes : new Dictionary < string , string > ( ) ,
99
- content : string . Empty ) ;
105
+ attributes : new Dictionary < string , string > ( ) ) ;
100
106
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
101
107
generator
102
108
. Setup ( mock => mock . GenerateForm (
@@ -124,7 +130,9 @@ public async Task ProcessAsync_GeneratesAntiForgeryCorrectly(bool? antiForgery,
124
130
// Assert
125
131
Assert . Equal ( "form" , output . TagName ) ;
126
132
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 ) ;
128
136
}
129
137
130
138
[ Fact ]
@@ -133,16 +141,17 @@ public async Task ProcessAsync_BindsRouteValuesFromTagHelperOutput()
133
141
// Arrange
134
142
var testViewContext = CreateViewContext ( ) ;
135
143
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" ) ) ;
137
147
var expectedAttribute = new KeyValuePair < string , string > ( "asp-ROUTEE-NotRoute" , "something" ) ;
138
148
var output = new TagHelperOutput (
139
149
"form" ,
140
150
attributes : new Dictionary < string , string > ( )
141
151
{
142
152
{ "asp-route-val" , "hello" } ,
143
153
{ "asp-roUte--Foo" , "bar" }
144
- } ,
145
- content : string . Empty ) ;
154
+ } ) ;
146
155
output . Attributes . Add ( expectedAttribute ) ;
147
156
148
157
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
@@ -184,7 +193,9 @@ public async Task ProcessAsync_BindsRouteValuesFromTagHelperOutput()
184
193
Assert . Equal ( "form" , output . TagName ) ;
185
194
var attribute = Assert . Single ( output . Attributes ) ;
186
195
Assert . Equal ( expectedAttribute , attribute ) ;
196
+ Assert . Empty ( output . PreContent ) ;
187
197
Assert . Empty ( output . Content ) ;
198
+ Assert . Empty ( output . PostContent ) ;
188
199
generator . Verify ( ) ;
189
200
}
190
201
@@ -194,11 +205,12 @@ public async Task ProcessAsync_CallsIntoGenerateFormWithExpectedParameters()
194
205
// Arrange
195
206
var viewContext = CreateViewContext ( ) ;
196
207
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" ) ) ;
198
211
var output = new TagHelperOutput (
199
212
"form" ,
200
- attributes : new Dictionary < string , string > ( ) ,
201
- content : string . Empty ) ;
213
+ attributes : new Dictionary < string , string > ( ) ) ;
202
214
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
203
215
generator
204
216
. Setup ( mock => mock . GenerateForm ( viewContext , "Index" , "Home" , null , "POST" , null ) )
@@ -220,7 +232,9 @@ public async Task ProcessAsync_CallsIntoGenerateFormWithExpectedParameters()
220
232
221
233
Assert . Equal ( "form" , output . TagName ) ;
222
234
Assert . Empty ( output . Attributes ) ;
235
+ Assert . Empty ( output . PreContent ) ;
223
236
Assert . Empty ( output . Content ) ;
237
+ Assert . Empty ( output . PostContent ) ;
224
238
}
225
239
226
240
[ Theory ]
@@ -238,14 +252,15 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsSpecified(string
238
252
attributes : new Dictionary < string , string >
239
253
{
240
254
{ "aCTiON" , htmlAction } ,
241
- } ,
242
- content : string . Empty ) ;
255
+ } ) ;
256
+
243
257
var context = new TagHelperContext (
244
258
allAttributes : new Dictionary < string , object > ( )
245
259
{
246
260
{ "METhod" , "POST" }
247
261
} ,
248
- uniqueId : "test" ) ;
262
+ uniqueId : "test" ,
263
+ getChildContentAsync : ( ) => Task . FromResult ( "Something" ) ) ;
249
264
250
265
// Act
251
266
await formTagHelper . ProcessAsync ( context , output ) ;
@@ -257,7 +272,9 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsSpecified(string
257
272
Assert . Equal ( htmlAction , attribute . Value ) ;
258
273
attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "METhod" ) ) ;
259
274
Assert . Equal ( "POST" , attribute . Value ) ;
275
+ Assert . Empty ( output . PreContent ) ;
260
276
Assert . Empty ( output . Content ) ;
277
+ Assert . Empty ( output . PostContent ) ;
261
278
}
262
279
263
280
[ Theory ]
@@ -266,11 +283,12 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsSpecified(string
266
283
[ InlineData ( null , "" ) ]
267
284
public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified (
268
285
bool ? antiForgery ,
269
- string expectedContent )
286
+ string expectedPostContent )
270
287
{
271
288
// Arrange
272
289
var viewContext = CreateViewContext ( ) ;
273
290
var generator = new Mock < IHtmlGenerator > ( ) ;
291
+
274
292
generator . Setup ( mock => mock . GenerateAntiForgery ( It . IsAny < ViewContext > ( ) ) )
275
293
. Returns ( new TagBuilder ( "input" ) ) ;
276
294
var formTagHelper = new FormTagHelper
@@ -284,9 +302,15 @@ public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified(
284
302
attributes : new Dictionary < string , string >
285
303
{
286
304
{ "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
+
290
314
291
315
// Act
292
316
await formTagHelper . ProcessAsync ( context , output ) ;
@@ -295,7 +319,9 @@ public async Task ProcessAsync_SupportsAntiForgeryIfActionIsSpecified(
295
319
Assert . Equal ( "form" , output . TagName ) ;
296
320
var attribute = Assert . Single ( output . Attributes ) ;
297
321
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 ) ;
299
325
}
300
326
301
327
[ Theory ]
@@ -314,8 +340,7 @@ public async Task ProcessAsync_ThrowsIfActionConflictsWithBoundAttributes(string
314
340
attributes : new Dictionary < string , string >
315
341
{
316
342
{ "action" , "my-action" } ,
317
- } ,
318
- content : string . Empty ) ;
343
+ } ) ;
319
344
if ( propertyName == "asp-route-" )
320
345
{
321
346
tagHelperOutput . Attributes . Add ( "asp-route-foo" , "bar" ) ;
0 commit comments