@@ -26,7 +26,7 @@ public async Task ProcessAsync_GeneratesExpectedOutput()
26
26
var metadataProvider = new DataAnnotationsModelMetadataProvider ( ) ;
27
27
var validationSummaryTagHelper = new ValidationSummaryTagHelper
28
28
{
29
- ValidationSummary = true
29
+ ValidationSummaryValue = "All"
30
30
} ;
31
31
32
32
var tagHelperContext = new TagHelperContext ( new Dictionary < string , object > ( ) ) ;
@@ -64,19 +64,18 @@ public async Task ProcessAsync_CallsIntoGenerateValidationSummaryWithExpectedPar
64
64
// Arrange
65
65
var validationSummaryTagHelper = new ValidationSummaryTagHelper
66
66
{
67
- ValidationSummary = true ,
68
- ValidationModelErrorsOnly = true
67
+ ValidationSummaryValue = "ModelOnly" ,
69
68
} ;
70
69
var output = new TagHelperOutput (
71
70
"div" ,
72
71
attributes : new Dictionary < string , string > ( ) ,
73
72
content : "Content of validation summary" ) ;
74
73
var expectedViewContext = CreateViewContext ( ) ;
75
74
var generator = new Mock < IHtmlGenerator > ( ) ;
76
- var setup = generator . Setup ( mock =>
77
- mock . GenerateValidationSummary ( expectedViewContext , true , null , null , null ) ) ;
78
- setup . Returns ( new TagBuilder ( "div" ) ) ;
79
- setup . Verifiable ( ) ;
75
+ generator
76
+ . Setup ( mock => mock . GenerateValidationSummary ( expectedViewContext , true , null , null , null ) )
77
+ . Returns ( new TagBuilder ( "div" ) )
78
+ . Verifiable ( ) ;
80
79
81
80
SetViewContextAndGenerator ( validationSummaryTagHelper , expectedViewContext , generator . Object ) ;
82
81
@@ -95,8 +94,7 @@ public async Task ProcessAsync_MergesTagBuilderFromGenerateValidationSummary()
95
94
// Arrange
96
95
var validationSummaryTagHelper = new ValidationSummaryTagHelper
97
96
{
98
- ValidationSummary = true ,
99
- ValidationModelErrorsOnly = true
97
+ ValidationSummaryValue = "ModelOnly"
100
98
} ;
101
99
var output = new TagHelperOutput (
102
100
"div" ,
@@ -112,13 +110,13 @@ public async Task ProcessAsync_MergesTagBuilderFromGenerateValidationSummary()
112
110
113
111
var expectedViewContext = CreateViewContext ( ) ;
114
112
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
115
- var setup = generator . Setup ( mock =>
116
- mock . GenerateValidationSummary ( It . IsAny < ViewContext > ( ) ,
117
- It . IsAny < bool > ( ) ,
118
- It . IsAny < string > ( ) ,
119
- It . IsAny < string > ( ) ,
120
- It . IsAny < object > ( ) ) ) ;
121
- setup . Returns ( tagBuilder ) ;
113
+ var setup = generator
114
+ . Setup ( mock => mock . GenerateValidationSummary ( It . IsAny < ViewContext > ( ) ,
115
+ It . IsAny < bool > ( ) ,
116
+ It . IsAny < string > ( ) ,
117
+ It . IsAny < string > ( ) ,
118
+ It . IsAny < object > ( ) ) )
119
+ . Returns ( tagBuilder ) ;
122
120
123
121
SetViewContextAndGenerator ( validationSummaryTagHelper , expectedViewContext , generator . Object ) ;
124
122
@@ -160,14 +158,18 @@ public async Task ProcessAsync_DoesNothingIfNullValidationSummary()
160
158
}
161
159
162
160
[ Theory ]
163
- [ InlineData ( true ) ]
164
- [ InlineData ( false ) ]
165
- public async Task ProcessAsync_GeneratesValidationSummaryIfModelErrorsNotNull ( bool validationModelErrorsOnly )
161
+ [ InlineData ( "All" ) ]
162
+ [ InlineData ( "all" ) ]
163
+ [ InlineData ( "ModelOnly" ) ]
164
+ [ InlineData ( "modelonly" ) ]
165
+ [ InlineData ( "None" ) ]
166
+ [ InlineData ( "none" ) ]
167
+ public async Task ProcessAsync_GeneratesValidationSummaryWhenNotNone_IgnoresCase ( string validationSummary )
166
168
{
167
169
// Arrange
168
170
var validationSummaryTagHelper = new ValidationSummaryTagHelper
169
171
{
170
- ValidationModelErrorsOnly = validationModelErrorsOnly
172
+ ValidationSummaryValue = validationSummary
171
173
} ;
172
174
var output = new TagHelperOutput (
173
175
"div" ,
@@ -180,14 +182,14 @@ public async Task ProcessAsync_GeneratesValidationSummaryIfModelErrorsNotNull(bo
180
182
181
183
var expectedViewContext = CreateViewContext ( ) ;
182
184
var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
183
- var setup = generator . Setup ( mock =>
184
- mock . GenerateValidationSummary ( It . IsAny < ViewContext > ( ) ,
185
- It . IsAny < bool > ( ) ,
186
- It . IsAny < string > ( ) ,
187
- It . IsAny < string > ( ) ,
188
- It . IsAny < object > ( ) ) ) ;
189
- setup . Returns ( tagBuilder ) ;
190
- setup . Verifiable ( ) ;
185
+ generator
186
+ . Setup ( mock => mock . GenerateValidationSummary ( It . IsAny < ViewContext > ( ) ,
187
+ It . IsAny < bool > ( ) ,
188
+ It . IsAny < string > ( ) ,
189
+ It . IsAny < string > ( ) ,
190
+ It . IsAny < object > ( ) ) )
191
+ . Returns ( tagBuilder )
192
+ . Verifiable ( ) ;
191
193
192
194
SetViewContextAndGenerator ( validationSummaryTagHelper , expectedViewContext , generator . Object ) ;
193
195
@@ -197,58 +199,42 @@ public async Task ProcessAsync_GeneratesValidationSummaryIfModelErrorsNotNull(bo
197
199
// Assert
198
200
Assert . Equal ( "div" , output . TagName ) ;
199
201
Assert . Empty ( output . Attributes ) ;
200
- Assert . Equal ( "Content of validation messageNew HTML" , output . Content ) ;
201
- generator . Verify ( ) ;
202
+
203
+ if ( ! validationSummary . Equals ( "None" , StringComparison . OrdinalIgnoreCase ) )
204
+ {
205
+ Assert . Equal ( "Content of validation messageNew HTML" , output . Content ) ;
206
+ generator . Verify ( ) ;
207
+ }
208
+ else
209
+ {
210
+ Assert . Equal ( "Content of validation message" , output . Content ) ;
211
+ }
202
212
}
203
213
204
- [ Theory ]
205
- [ InlineData ( true ) ]
206
- [ InlineData ( false ) ]
207
- public async Task ProcessAsync_GeneratesValidationSummaryWhenProvided ( bool validationSummary )
214
+ [ Fact ]
215
+ public async Task ProcessAsync_ThrowsWhenInvalidValidationSummaryValue ( )
208
216
{
209
217
// Arrange
210
218
var validationSummaryTagHelper = new ValidationSummaryTagHelper
211
219
{
212
- ValidationSummary = validationSummary
220
+ ValidationSummaryValue = "Hello World"
213
221
} ;
214
222
var output = new TagHelperOutput (
215
223
"div" ,
216
224
attributes : new Dictionary < string , string > ( ) ,
217
225
content : "Content of validation message" ) ;
218
- var tagBuilder = new TagBuilder ( "span2" )
219
- {
220
- InnerHtml = "New HTML"
221
- } ;
222
-
223
226
var expectedViewContext = CreateViewContext ( ) ;
224
- var generator = new Mock < IHtmlGenerator > ( MockBehavior . Strict ) ;
225
- var setup = generator . Setup ( mock =>
226
- mock . GenerateValidationSummary ( It . IsAny < ViewContext > ( ) ,
227
- It . IsAny < bool > ( ) ,
228
- It . IsAny < string > ( ) ,
229
- It . IsAny < string > ( ) ,
230
- It . IsAny < object > ( ) ) ) ;
231
- setup . Returns ( tagBuilder ) ;
232
- setup . Verifiable ( ) ;
233
-
234
- SetViewContextAndGenerator ( validationSummaryTagHelper , expectedViewContext , generator . Object ) ;
227
+ var expectedMessage = "Cannot determine validation-summary. Acceptable values are 'All', 'ModelOnly' " +
228
+ "and 'None'." ;
235
229
236
230
// Act
237
- await validationSummaryTagHelper . ProcessAsync ( context : null , output : output ) ;
231
+ var ex = await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) =>
232
+ {
233
+ await validationSummaryTagHelper . ProcessAsync ( context : null , output : output ) ;
234
+ } ) ;
238
235
239
236
// Assert
240
- Assert . Equal ( "div" , output . TagName ) ;
241
- Assert . Empty ( output . Attributes ) ;
242
-
243
- if ( validationSummary )
244
- {
245
- Assert . Equal ( "Content of validation messageNew HTML" , output . Content ) ;
246
- generator . Verify ( ) ;
247
- }
248
- else
249
- {
250
- Assert . Equal ( "Content of validation message" , output . Content ) ;
251
- }
237
+ Assert . Equal ( expectedMessage , ex . Message ) ;
252
238
}
253
239
254
240
private static ViewContext CreateViewContext ( )
0 commit comments