Skip to content

Commit 76d54f0

Browse files
committed
- got tests working
1 parent 384eca2 commit 76d54f0

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

Our.Umbraco.TagHelpers.Tests/OurIfTests.cs renamed to Our.Umbraco.TagHelpers.Tests/IncludeIfTagHelperTests.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Our.Umbraco.TagHelpers.Tests
99
{
10-
public class Tests
10+
public class IncludeIfTagHelperTests
1111
{
1212
[Test]
1313
public async Task Given_True_Value_Return_Contents()
@@ -19,20 +19,51 @@ public async Task Given_True_Value_Return_Contents()
1919
var tagHelperOutput = GetTagHelperOutput(
2020
attributes: new TagHelperAttributeList(),
2121
childContent: childContent);
22+
tagHelperOutput.Content.SetContent(childContent);
23+
2224
var tagHelper = new IncludeIfTagHelper();
25+
tagHelper.Predicate = true;
2326

2427
// Act
2528
await tagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);
2629

30+
var content = tagHelperOutput.Content.GetContent();
31+
Console.WriteLine("Value:" + content);
32+
2733
// Assert
2834
Assert.AreEqual(childContent, tagHelperOutput.Content.GetContent());
2935
}
3036

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+
3162
private static TagHelperContext GetTagHelperContext(string id = "testid")
3263
{
3364
return new TagHelperContext(
3465
tagName: "p",
35-
allAttributes: new TagHelperAttributeList() { new TagHelperAttribute("our-if", true) },
66+
allAttributes: new TagHelperAttributeList(),
3667
items: new Dictionary<object, object>(),
3768
uniqueId: id);
3869
}
@@ -50,8 +81,8 @@ private static TagHelperOutput GetTagHelperOutput(
5081
getChildContentAsync: (useCachedResult, encoder) =>
5182
{
5283
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);
5586
});
5687
}
5788
}

0 commit comments

Comments
 (0)