@@ -9,39 +9,65 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
9
9
public class TagHelperOutputTest
10
10
{
11
11
[ Fact ]
12
- public void TagName_CannotSetToNullInCtor ( )
12
+ public void TagName_CanSetToNullInCtor ( )
13
13
{
14
14
// Arrange & Act
15
15
var tagHelperOutput = new TagHelperOutput ( null ) ;
16
16
17
17
// Assert
18
- Assert . Empty ( tagHelperOutput . TagName ) ;
18
+ Assert . Null ( tagHelperOutput . TagName ) ;
19
19
}
20
20
21
21
[ Fact ]
22
- public void TagName_CannotSetToNull ( )
22
+ public void TagName_CanSetToNull ( )
23
23
{
24
- // Arrange
25
- var tagHelperOutput = new TagHelperOutput ( "p" ) ;
24
+ // Arrange & Act
25
+ var tagHelperOutput = new TagHelperOutput ( "p" )
26
+ {
27
+ TagName = null
28
+ } ;
26
29
27
- // Act
28
- tagHelperOutput . TagName = null ;
30
+ // Assert
31
+ Assert . Null ( tagHelperOutput . TagName ) ;
32
+ }
33
+
34
+ [ Fact ]
35
+ public void Content_CanSetToNull ( )
36
+ {
37
+ // Arrange & Act
38
+ var tagHelperOutput = new TagHelperOutput ( "p" )
39
+ {
40
+ Content = null
41
+ } ;
29
42
30
43
// Assert
31
- Assert . Empty ( tagHelperOutput . TagName ) ;
44
+ Assert . Null ( tagHelperOutput . Content ) ;
32
45
}
33
46
34
47
[ Fact ]
35
- public void Content_CannotSetToNull ( )
48
+ public void PreContent_CanSetToNull ( )
36
49
{
37
- // Arrange
38
- var tagHelperOutput = new TagHelperOutput ( "p" ) ;
50
+ // Arrange & Act
51
+ var tagHelperOutput = new TagHelperOutput ( "p" )
52
+ {
53
+ PreContent = null
54
+ } ;
39
55
40
- // Act
41
- tagHelperOutput . Content = null ;
56
+ // Assert
57
+ Assert . Null ( tagHelperOutput . PreContent ) ;
58
+ }
59
+
60
+ [ Fact ]
61
+ public void PostContent_CanSetToNull ( )
62
+ {
63
+ // Arrange & Act
64
+ var tagHelperOutput = new TagHelperOutput ( "p" )
65
+ {
66
+ PostContent = null
67
+ } ;
42
68
43
69
// Assert
44
- Assert . Empty ( tagHelperOutput . Content ) ;
70
+ Assert . Null ( tagHelperOutput . PostContent ) ;
45
71
}
46
72
47
73
[ Fact ]
@@ -119,9 +145,10 @@ public void GenerateStartTag_ReturnsNothingIfWhitespaceTagName()
119
145
{
120
146
{ "class" , "btn" } ,
121
147
{ "something" , " spaced " }
122
- } ) ;
123
-
124
- tagHelperOutput . SelfClosing = true ;
148
+ } )
149
+ {
150
+ SelfClosing = true
151
+ } ;
125
152
126
153
// Act
127
154
var output = tagHelperOutput . GenerateStartTag ( ) ;
@@ -135,9 +162,10 @@ public void GenerateStartTag_ReturnsNothingIfWhitespaceTagName()
135
162
public void GenerateEndTag_ReturnsNothingIfWhitespaceTagName ( )
136
163
{
137
164
// Arrange
138
- var tagHelperOutput = new TagHelperOutput ( " " ) ; ;
139
-
140
- tagHelperOutput . Content = "Hello World" ;
165
+ var tagHelperOutput = new TagHelperOutput ( " " )
166
+ {
167
+ Content = "Hello World"
168
+ } ;
141
169
142
170
// Act
143
171
var output = tagHelperOutput . GenerateEndTag ( ) ;
@@ -147,12 +175,46 @@ public void GenerateEndTag_ReturnsNothingIfWhitespaceTagName()
147
175
}
148
176
149
177
[ Fact ]
150
- public void GenerateContent_ReturnsContent ( )
178
+ public void GeneratePreContent_ReturnsPreContent ( )
151
179
{
152
180
// Arrange
153
- var tagHelperOutput = new TagHelperOutput ( "p" ) ;
181
+ var tagHelperOutput = new TagHelperOutput ( "p" )
182
+ {
183
+ PreContent = "Hello World"
184
+ } ;
185
+
186
+ // Act
187
+ var output = tagHelperOutput . GeneratePreContent ( ) ;
188
+
189
+ // Assert
190
+ Assert . Equal ( "Hello World" , output ) ;
191
+ }
192
+
193
+ [ Fact ]
194
+ public void GeneratePreContent_ReturnsNothingIfSelfClosing ( )
195
+ {
196
+ // Arrange
197
+ var tagHelperOutput = new TagHelperOutput ( "p" )
198
+ {
199
+ SelfClosing = true ,
200
+ PreContent = "Hello World"
201
+ } ;
202
+
203
+ // Act
204
+ var output = tagHelperOutput . GeneratePreContent ( ) ;
205
+
206
+ // Assert
207
+ Assert . Empty ( output ) ;
208
+ }
154
209
155
- tagHelperOutput . Content = "Hello World" ;
210
+ [ Fact ]
211
+ public void GenerateContent_ReturnsContent ( )
212
+ {
213
+ // Arrange
214
+ var tagHelperOutput = new TagHelperOutput ( "p" )
215
+ {
216
+ Content = "Hello World"
217
+ } ;
156
218
157
219
// Act
158
220
var output = tagHelperOutput . GenerateContent ( ) ;
@@ -168,18 +230,50 @@ public void GenerateContent_ReturnsNothingIfSelfClosing()
168
230
// Arrange
169
231
var tagHelperOutput = new TagHelperOutput ( "p" )
170
232
{
171
- SelfClosing = true
233
+ SelfClosing = true ,
234
+ Content = "Hello World"
172
235
} ;
173
236
174
- tagHelperOutput . Content = "Hello World" ;
175
-
176
237
// Act
177
238
var output = tagHelperOutput . GenerateContent ( ) ;
178
239
179
240
// Assert
180
241
Assert . Empty ( output ) ;
181
242
}
182
243
244
+ [ Fact ]
245
+ public void GeneratePostContent_ReturnsPostContent ( )
246
+ {
247
+ // Arrange
248
+ var tagHelperOutput = new TagHelperOutput ( "p" )
249
+ {
250
+ PostContent = "Hello World"
251
+ } ;
252
+
253
+ // Act
254
+ var output = tagHelperOutput . GeneratePostContent ( ) ;
255
+
256
+ // Assert
257
+ Assert . Equal ( "Hello World" , output ) ;
258
+ }
259
+
260
+ [ Fact ]
261
+ public void GeneratePostContent_ReturnsNothingIfSelfClosing ( )
262
+ {
263
+ // Arrange
264
+ var tagHelperOutput = new TagHelperOutput ( "p" )
265
+ {
266
+ SelfClosing = true ,
267
+ PostContent = "Hello World"
268
+ } ;
269
+
270
+ // Act
271
+ var output = tagHelperOutput . GeneratePostContent ( ) ;
272
+
273
+ // Assert
274
+ Assert . Empty ( output ) ;
275
+ }
276
+
183
277
[ Fact ]
184
278
public void GenerateEndTag_ReturnsEndTag ( )
185
279
{
@@ -209,6 +303,54 @@ public void GenerateEndTag_ReturnsNothingIfSelfClosing()
209
303
Assert . Empty ( output ) ;
210
304
}
211
305
306
+ [ Fact ]
307
+ public void SuppressOutput_Sets_TagName_Content_PreContent_PostContent_ToNull ( )
308
+ {
309
+ // Arrange
310
+ var tagHelperOutput = new TagHelperOutput ( "p" )
311
+ {
312
+ PreContent = "Pre Content" ,
313
+ Content = "Content" ,
314
+ PostContent = "Post Content"
315
+ } ;
316
+
317
+ // Act
318
+ tagHelperOutput . SuppressOutput ( ) ;
319
+
320
+ // Assert
321
+ Assert . Null ( tagHelperOutput . TagName ) ;
322
+ Assert . Null ( tagHelperOutput . PreContent ) ;
323
+ Assert . Null ( tagHelperOutput . Content ) ;
324
+ Assert . Null ( tagHelperOutput . PostContent ) ;
325
+ }
326
+
327
+ [ Fact ]
328
+ public void SuppressOutput_PreventsTagOutput ( )
329
+ {
330
+ // Arrange
331
+ var tagHelperOutput = new TagHelperOutput ( "p" ,
332
+ attributes : new Dictionary < string , string >
333
+ {
334
+ { "class" , "btn" } ,
335
+ { "something" , " spaced " }
336
+ } )
337
+ {
338
+ PreContent = "Pre Content" ,
339
+ Content = "Content" ,
340
+ PostContent = "Post Content"
341
+ } ;
342
+
343
+ // Act
344
+ tagHelperOutput . SuppressOutput ( ) ;
345
+
346
+ // Assert
347
+ Assert . Empty ( tagHelperOutput . GenerateStartTag ( ) ) ;
348
+ Assert . Null ( tagHelperOutput . GeneratePreContent ( ) ) ;
349
+ Assert . Null ( tagHelperOutput . GenerateContent ( ) ) ;
350
+ Assert . Null ( tagHelperOutput . GeneratePostContent ( ) ) ;
351
+ Assert . Empty ( tagHelperOutput . GenerateEndTag ( ) ) ;
352
+ }
353
+
212
354
[ Theory ]
213
355
[ InlineData ( "class" , "ClASs" ) ]
214
356
[ InlineData ( "CLaSs" , "class" ) ]
0 commit comments