7
7
8
8
namespace Our . Umbraco . TagHelpers . Tests
9
9
{
10
- public class Tests
10
+ public class IncludeIfTagHelperTests
11
11
{
12
12
[ Test ]
13
13
public async Task Given_True_Value_Return_Contents ( )
@@ -19,20 +19,51 @@ public async Task Given_True_Value_Return_Contents()
19
19
var tagHelperOutput = GetTagHelperOutput (
20
20
attributes : new TagHelperAttributeList ( ) ,
21
21
childContent : childContent ) ;
22
+ tagHelperOutput . Content . SetContent ( childContent ) ;
23
+
22
24
var tagHelper = new IncludeIfTagHelper ( ) ;
25
+ tagHelper . Predicate = true ;
23
26
24
27
// Act
25
28
await tagHelper . ProcessAsync ( tagHelperContext , tagHelperOutput ) ;
26
29
30
+ var content = tagHelperOutput . Content . GetContent ( ) ;
31
+ Console . WriteLine ( "Value:" + content ) ;
32
+
27
33
// Assert
28
34
Assert . AreEqual ( childContent , tagHelperOutput . Content . GetContent ( ) ) ;
29
35
}
30
36
37
+ [ Test ]
38
+ public async Task Given_False_Value_Return_Empty ( )
39
+ {
40
+ // Arrange
41
+ var id = "unique-id" ;
42
+ var childContent = "original-child-content" ;
43
+ var tagHelperContext = GetTagHelperContext ( id ) ;
44
+ var tagHelperOutput = GetTagHelperOutput (
45
+ attributes : new TagHelperAttributeList ( ) ,
46
+ childContent : childContent ) ;
47
+ tagHelperOutput . Content . SetContent ( childContent ) ;
48
+
49
+ var tagHelper = new IncludeIfTagHelper ( ) ;
50
+ tagHelper . Predicate = false ;
51
+
52
+ // Act
53
+ await tagHelper . ProcessAsync ( tagHelperContext , tagHelperOutput ) ;
54
+
55
+ var content = tagHelperOutput . Content . GetContent ( ) ;
56
+ Console . WriteLine ( "Value:" + content ) ;
57
+
58
+ // Assert
59
+ Assert . AreEqual ( string . Empty , tagHelperOutput . Content . GetContent ( ) ) ;
60
+ }
61
+
31
62
private static TagHelperContext GetTagHelperContext ( string id = "testid" )
32
63
{
33
64
return new TagHelperContext (
34
65
tagName : "p" ,
35
- allAttributes : new TagHelperAttributeList ( ) { new TagHelperAttribute ( "our-if" , true ) } ,
66
+ allAttributes : new TagHelperAttributeList ( ) ,
36
67
items : new Dictionary < object , object > ( ) ,
37
68
uniqueId : id ) ;
38
69
}
@@ -50,8 +81,8 @@ private static TagHelperOutput GetTagHelperOutput(
50
81
getChildContentAsync : ( useCachedResult , encoder ) =>
51
82
{
52
83
var tagHelperContent = new DefaultTagHelperContent ( ) ;
53
- tagHelperContent . SetHtmlContent ( childContent ) ;
54
- return Task . FromResult < TagHelperContent > ( tagHelperContent ) ;
84
+ var content = tagHelperContent . SetHtmlContent ( childContent ) ;
85
+ return Task . FromResult < TagHelperContent > ( content ) ;
55
86
} ) ;
56
87
}
57
88
}
0 commit comments