@@ -50,14 +50,14 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
50
50
} ,
51
51
content : "Something" ) ;
52
52
var urlHelper = new Mock < IUrlHelper > ( ) ;
53
- var setup = urlHelper . Setup ( mock =>
54
- mock . Action ( It . IsAny < string > ( ) ,
55
- It . IsAny < string > ( ) ,
56
- It . IsAny < object > ( ) ,
57
- It . IsAny < string > ( ) ,
58
- It . IsAny < string > ( ) ,
59
- It . IsAny < string > ( ) ) ) ;
60
- setup . Returns ( "home/index" ) ;
53
+ urlHelper
54
+ . Setup ( mock => mock . Action ( It . IsAny < string > ( ) ,
55
+ It . IsAny < string > ( ) ,
56
+ It . IsAny < object > ( ) ,
57
+ It . IsAny < string > ( ) ,
58
+ It . IsAny < string > ( ) ,
59
+ It . IsAny < string > ( ) ) )
60
+ . Returns ( "home/index" ) ;
61
61
62
62
var htmlGenerator = new TestableHtmlGenerator ( metadataProvider , urlHelper . Object ) ;
63
63
var viewContext = TestableHtmlGenerator . GetViewContext ( model : null ,
@@ -72,6 +72,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
72
72
await formTagHelper . ProcessAsync ( tagHelperContext , output ) ;
73
73
74
74
// Assert
75
+ Assert . Equal ( 3 , output . Attributes . Count ) ;
75
76
var attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "id" ) ) ;
76
77
Assert . Equal ( "myform" , attribute . Value ) ;
77
78
attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "method" ) ) ;
@@ -89,7 +90,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
89
90
public async Task ProcessAsync_GeneratesAntiForgeryCorrectly ( bool ? antiForgery , string expectedContent )
90
91
{
91
92
// Arrange
92
- var expectedViewContext = CreateViewContext ( ) ;
93
+ var viewContext = CreateViewContext ( ) ;
93
94
var formTagHelper = new FormTagHelper
94
95
{
95
96
Action = "Index" ,
@@ -102,18 +103,20 @@ public async Task ProcessAsync_GeneratesAntiForgeryCorrectly(bool? antiForgery,
102
103
attributes : new Dictionary < string , string > ( ) ,
103
104
content : string . Empty ) ;
104
105
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
105
- generator . Setup ( mock =>
106
- mock . GenerateForm ( It . IsAny < ViewContext > ( ) ,
107
- It . IsAny < string > ( ) ,
108
- It . IsAny < string > ( ) ,
109
- It . IsAny < object > ( ) ,
110
- It . IsAny < string > ( ) ,
111
- It . IsAny < object > ( ) ) )
112
- . Returns ( new TagBuilder ( "form" ) ) ;
113
- generator . Setup ( mock => mock . GenerateAntiForgery ( expectedViewContext ) )
106
+ generator
107
+ . Setup ( mock => mock . GenerateForm (
108
+ It . IsAny < ViewContext > ( ) ,
109
+ It . IsAny < string > ( ) ,
110
+ It . IsAny < string > ( ) ,
111
+ It . IsAny < object > ( ) ,
112
+ It . IsAny < string > ( ) ,
113
+ It . IsAny < object > ( ) ) )
114
+ . Returns ( new TagBuilder ( "form" ) ) ;
115
+
116
+ generator . Setup ( mock => mock . GenerateAntiForgery ( viewContext ) )
114
117
. Returns ( new TagBuilder ( "input" ) ) ;
115
118
116
- SetViewContextAndGenerator ( formTagHelper , expectedViewContext , generator . Object ) ;
119
+ SetViewContextAndGenerator ( formTagHelper , viewContext , generator . Object ) ;
117
120
118
121
// Act
119
122
await formTagHelper . ProcessAsync ( context , output ) ;
@@ -125,7 +128,7 @@ public async Task ProcessAsync_GeneratesAntiForgeryCorrectly(bool? antiForgery,
125
128
}
126
129
127
130
[ Fact ]
128
- public async Task ProcessAsync_UnderstandsRouteValues ( )
131
+ public async Task ProcessAsync_BindsRouteValuesFromTagHelperOutput ( )
129
132
{
130
133
// Arrange
131
134
var testViewContext = CreateViewContext ( ) ;
@@ -136,39 +139,42 @@ public async Task ProcessAsync_UnderstandsRouteValues()
136
139
} ;
137
140
var context = new TagHelperContext (
138
141
allAttributes : new Dictionary < string , object > ( ) ) ;
142
+ var expectedAttribute = new KeyValuePair < string , string > ( "ROUTEE-NotRoute" , "something" ) ;
139
143
var output = new TagHelperOutput (
140
144
"form" ,
141
145
attributes : new Dictionary < string , string > ( )
142
146
{
143
147
{ "route-val" , "hello" } ,
144
- { "roUte--Foo" , "bar" } ,
145
- { "ROUTEE-NotRoute" , "something" }
148
+ { "roUte--Foo" , "bar" }
146
149
} ,
147
150
content : string . Empty ) ;
148
- var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
149
- var setup = generator . Setup ( mock =>
150
- mock . GenerateForm ( It . IsAny < ViewContext > ( ) ,
151
- It . IsAny < string > ( ) ,
152
- It . IsAny < string > ( ) ,
153
- It . IsAny < object > ( ) ,
154
- It . IsAny < string > ( ) ,
155
- It . IsAny < object > ( ) ) ) ;
156
- setup . Callback < ViewContext , string , string , object , string , object > (
157
- ( viewContext , actionName , controllerName , routeValues , method , htmlAttributes ) =>
158
- {
159
- // Fixes Roslyn bug with lambdas
160
- generator . ToString ( ) ;
151
+ output . Attributes . Add ( expectedAttribute ) ;
161
152
162
- var routeValueDictionary = ( Dictionary < string , object > ) routeValues ;
163
-
164
- Assert . Equal ( 2 , routeValueDictionary . Count ) ;
165
- var routeValue = Assert . Single ( routeValueDictionary , kvp => kvp . Key . Equals ( "val" ) ) ;
166
- Assert . Equal ( "hello" , routeValue . Value ) ;
167
- routeValue = Assert . Single ( routeValueDictionary , kvp => kvp . Key . Equals ( "-Foo" ) ) ;
168
- Assert . Equal ( "bar" , routeValue . Value ) ;
169
- } ) ;
170
- setup . Returns ( new TagBuilder ( "form" ) ) ;
171
- setup . Verifiable ( ) ;
153
+ var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
154
+ generator
155
+ . Setup ( mock => mock . GenerateForm (
156
+ It . IsAny < ViewContext > ( ) ,
157
+ It . IsAny < string > ( ) ,
158
+ It . IsAny < string > ( ) ,
159
+ It . IsAny < object > ( ) ,
160
+ It . IsAny < string > ( ) ,
161
+ It . IsAny < object > ( ) ) )
162
+ . Callback < ViewContext , string , string , object , string , object > (
163
+ ( viewContext , actionName , controllerName , routeValues , method , htmlAttributes ) =>
164
+ {
165
+ // Fixes Roslyn bug with lambdas
166
+ generator . ToString ( ) ;
167
+
168
+ var routeValueDictionary = ( Dictionary < string , object > ) routeValues ;
169
+
170
+ Assert . Equal ( 2 , routeValueDictionary . Count ) ;
171
+ var routeValue = Assert . Single ( routeValueDictionary , kvp => kvp . Key . Equals ( "val" ) ) ;
172
+ Assert . Equal ( "hello" , routeValue . Value ) ;
173
+ routeValue = Assert . Single ( routeValueDictionary , kvp => kvp . Key . Equals ( "-Foo" ) ) ;
174
+ Assert . Equal ( "bar" , routeValue . Value ) ;
175
+ } )
176
+ . Returns ( new TagBuilder ( "form" ) )
177
+ . Verifiable ( ) ;
172
178
173
179
SetViewContextAndGenerator ( formTagHelper , testViewContext , generator . Object ) ;
174
180
@@ -177,7 +183,7 @@ public async Task ProcessAsync_UnderstandsRouteValues()
177
183
178
184
Assert . Equal ( "form" , output . TagName ) ;
179
185
var attribute = Assert . Single ( output . Attributes ) ;
180
- Assert . Equal ( "something" , attribute . Value ) ;
186
+ Assert . Equal ( expectedAttribute , attribute ) ;
181
187
Assert . Empty ( output . Content ) ;
182
188
generator . Verify ( ) ;
183
189
}
@@ -186,7 +192,7 @@ public async Task ProcessAsync_UnderstandsRouteValues()
186
192
public async Task ProcessAsync_CallsIntoGenerateFormWithExpectedParameters ( )
187
193
{
188
194
// Arrange
189
- var expectedViewContext = CreateViewContext ( ) ;
195
+ var viewContext = CreateViewContext ( ) ;
190
196
var formTagHelper = new FormTagHelper
191
197
{
192
198
Action = "Index" ,
@@ -201,13 +207,13 @@ public async Task ProcessAsync_CallsIntoGenerateFormWithExpectedParameters()
201
207
attributes : new Dictionary < string , string > ( ) ,
202
208
content : string . Empty ) ;
203
209
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
204
- var setup = generator . Setup ( mock =>
205
- mock . GenerateForm ( expectedViewContext , "Index" , "Home" , null , "POST" , null ) ) ;
206
- setup . Returns ( new TagBuilder ( "form" ) ) ;
207
- setup . Verifiable ( ) ;
210
+ generator
211
+ . Setup ( mock => mock . GenerateForm ( viewContext , "Index" , "Home" , null , "POST" , null ) )
212
+ . Returns ( new TagBuilder ( "form" ) )
213
+ . Verifiable ( ) ;
208
214
209
215
SetViewContextAndGenerator ( formTagHelper ,
210
- expectedViewContext ,
216
+ viewContext ,
211
217
generator . Object ) ;
212
218
213
219
// Act & Assert
@@ -243,6 +249,7 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsURL()
243
249
244
250
// Assert
245
251
Assert . Equal ( "form" , output . TagName ) ;
252
+ Assert . Equal ( 2 , output . Attributes . Count ) ;
246
253
var attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "aCTiON" ) ) ;
247
254
Assert . Equal ( "http://www.contoso.com" , attribute . Value ) ;
248
255
attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "METhod" ) ) ;
@@ -254,10 +261,10 @@ public async Task ProcessAsync_RestoresBoundAttributesIfActionIsURL()
254
261
[ InlineData ( true , "<input />" ) ]
255
262
[ InlineData ( false , "" ) ]
256
263
[ InlineData ( null , "" ) ]
257
- public async Task ProcessAsync_AllowsAntiForgeryIfActionIsURL ( bool ? antiForgery , string expectedContent )
264
+ public async Task ProcessAsync_SupportsAntiForgeryIfActionIsURL ( bool ? antiForgery , string expectedContent )
258
265
{
259
266
// Arrange
260
- var expectedViewContext = CreateViewContext ( ) ;
267
+ var viewContext = CreateViewContext ( ) ;
261
268
var generator = new Mock < IHtmlGenerator > ( ) ;
262
269
generator . Setup ( mock => mock . GenerateAntiForgery ( It . IsAny < ViewContext > ( ) ) )
263
270
. Returns ( new TagBuilder ( "input" ) ) ;
@@ -267,7 +274,7 @@ public async Task ProcessAsync_AllowsAntiForgeryIfActionIsURL(bool? antiForgery,
267
274
AntiForgery = antiForgery ,
268
275
} ;
269
276
SetViewContextAndGenerator ( formTagHelper ,
270
- expectedViewContext ,
277
+ viewContext ,
271
278
generator . Object ) ;
272
279
var output = new TagHelperOutput ( "form" ,
273
280
attributes : new Dictionary < string , string > ( ) ,
@@ -283,8 +290,8 @@ public async Task ProcessAsync_AllowsAntiForgeryIfActionIsURL(bool? antiForgery,
283
290
284
291
// Assert
285
292
Assert . Equal ( "form" , output . TagName ) ;
286
- var attribute = Assert . Single ( output . Attributes , kvp => kvp . Key . Equals ( "aCTiON" ) ) ;
287
- Assert . Equal ( " http://www.contoso.com", attribute . Value ) ;
293
+ var attribute = Assert . Single ( output . Attributes ) ;
294
+ Assert . Equal ( new KeyValuePair < string , string > ( "aCTiON" , " http://www.contoso.com") , attribute ) ;
288
295
Assert . Equal ( expectedContent , output . Content ) ;
289
296
}
290
297
@@ -298,8 +305,8 @@ public async Task ProcessAsync_ThrowsIfActionIsUrlWithSpecifiedController()
298
305
Controller = "Home" ,
299
306
Method = "POST"
300
307
} ;
301
- var expectedErrorMessage = "Cannot determine an Action for <form>. A <form> with a URL-based Action " +
302
- "must not have attributes starting with route- or a Controller attribute." ;
308
+ var expectedErrorMessage = "Cannot determine an action for <form>. A <form> with a URL-based action " +
309
+ "must not have attributes starting with route- or a controller attribute." ;
303
310
var tagHelperOutput = new TagHelperOutput (
304
311
"form" ,
305
312
attributes : new Dictionary < string , string > ( ) ,
@@ -323,8 +330,8 @@ public async Task ProcessAsync_ThrowsIfActionIsUrlWithSpecifiedRoutes()
323
330
Action = "http://www.contoso.com" ,
324
331
Method = "POST"
325
332
} ;
326
- var expectedErrorMessage = "Cannot determine an Action for <form>. A <form> with a URL-based Action " +
327
- "must not have attributes starting with route- or a Controller attribute." ;
333
+ var expectedErrorMessage = "Cannot determine an action for <form>. A <form> with a URL-based action " +
334
+ "must not have attributes starting with route- or a controller attribute." ;
328
335
var tagHelperOutput = new TagHelperOutput (
329
336
"form" ,
330
337
attributes : new Dictionary < string , string >
0 commit comments