本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TagHelperExecutionContext.GetChildContentAsync方法的具体用法?C# TagHelperExecutionContext.GetChildContentAsync怎么用?C# TagHelperExecutionContext.GetChildContentAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext
的用法示例。
在下文中一共展示了TagHelperExecutionContext.GetChildContentAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetChildContentAsync_CachesValue
public async Task GetChildContentAsync_CachesValue()
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var expectedContent = string.Empty;
var executionContext = new TagHelperExecutionContext(
"p",
selfClosing: false,
items: null,
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
if (string.IsNullOrEmpty(expectedContent))
{
expectedContent = "Hello from child content: " + Guid.NewGuid().ToString();
}
defaultTagHelperContent.SetContent(expectedContent);
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync();
var content2 = await executionContext.GetChildContentAsync();
// Assert
Assert.Equal(expectedContent, content1.GetContent());
Assert.Equal(expectedContent, content2.GetContent());
}
示例2: GetChildContentAsync_CachesValue
public async Task GetChildContentAsync_CachesValue()
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var content = string.Empty;
var expectedContent = string.Empty;
var executionContext = new TagHelperExecutionContext(
"p",
tagMode: TagMode.StartTagAndEndTag,
items: new Dictionary<object, object>(),
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
if (string.IsNullOrEmpty(expectedContent))
{
content = "Hello from child content: " + Guid.NewGuid().ToString();
expectedContent = $"HtmlEncode[[{content}]]";
}
defaultTagHelperContent.SetContent(content);
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync(useCachedResult: true);
var content2 = await executionContext.GetChildContentAsync(useCachedResult: true);
// Assert
Assert.Equal(expectedContent, content1.GetContent(new HtmlTestEncoder()));
Assert.Equal(expectedContent, content2.GetContent(new HtmlTestEncoder()));
}
示例3: GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled
public async Task GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled()
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var executionContext = new TagHelperExecutionContext(
"p",
selfClosing: false,
items: null,
uniqueId: string.Empty,
executeChildContentAsync: () => { return Task.FromResult(result: true); },
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync();
content1.Append("Hello");
var content2 = await executionContext.GetChildContentAsync();
content2.Append("World!");
// Assert
Assert.NotSame(content1, content2);
Assert.Empty((await executionContext.GetChildContentAsync()).GetContent());
}
示例4: GetChildContentAsync_CanExecuteChildrenMoreThanOnce
public async Task GetChildContentAsync_CanExecuteChildrenMoreThanOnce()
{
// Arrange
var executionCount = 0;
var executionContext = new TagHelperExecutionContext(
"p",
tagMode: TagMode.StartTagAndEndTag,
items: new Dictionary<object, object>(),
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
executionCount++;
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => new DefaultTagHelperContent());
// Act
await executionContext.GetChildContentAsync(useCachedResult: false);
await executionContext.GetChildContentAsync(useCachedResult: false);
// Assert
Assert.Equal(2, executionCount);
}
示例5: GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled
public async Task GetChildContentAsync_ReturnsNewObjectEveryTimeItIsCalled(bool useCachedResult)
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var executionContext = new TagHelperExecutionContext(
"p",
tagMode: TagMode.StartTagAndEndTag,
items: new Dictionary<object, object>(),
uniqueId: string.Empty,
executeChildContentAsync: () => { return Task.FromResult(result: true); },
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
// Act
var content1 = await executionContext.GetChildContentAsync(useCachedResult);
content1.Append("Hello");
var content2 = await executionContext.GetChildContentAsync(useCachedResult);
content2.Append("World!");
// Assert
Assert.NotSame(content1, content2);
var content3 = await executionContext.GetChildContentAsync(useCachedResult);
Assert.Empty(content3.GetContent(new HtmlTestEncoder()));
}
示例6: WriteTagHelperAsync_WritesContentAppropriately
public async Task WriteTagHelperAsync_WritesContentAppropriately(
bool childContentRetrieved, string input, string expected)
{
// Arrange
var defaultTagHelperContent = new DefaultTagHelperContent();
var writer = new StringCollectionTextWriter(Encoding.UTF8);
var context = CreateViewContext(writer);
var tagHelperExecutionContext = new TagHelperExecutionContext(
tagName: "p",
tagMode: TagMode.StartTagAndEndTag,
items: new Dictionary<object, object>(),
uniqueId: string.Empty,
executeChildContentAsync: () =>
{
defaultTagHelperContent.AppendEncoded(input);
return Task.FromResult(result: true);
},
startTagHelperWritingScope: () => { },
endTagHelperWritingScope: () => defaultTagHelperContent);
tagHelperExecutionContext.Output = new TagHelperOutput("p", new TagHelperAttributeList());
if (childContentRetrieved)
{
await tagHelperExecutionContext.GetChildContentAsync(useCachedResult: true);
}
// Act
var page = CreatePage(p =>
{
p.HtmlEncoder = new CommonTestEncoder();
p.WriteTagHelperAsync(tagHelperExecutionContext).Wait();
}, context);
await page.ExecuteAsync();
// Assert
Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(writer.Content));
}