当前位置: 首页>>代码示例>>C#>>正文


C# TagHelperExecutionContext.GetChildContentAsync方法代码示例

本文整理汇总了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());
        }
开发者ID:billwaddyjr,项目名称:Razor,代码行数:32,代码来源:TagHelperExecutionContextTest.cs

示例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()));
        }
开发者ID:leloulight,项目名称:Razor,代码行数:34,代码来源:TagHelperExecutionContextTest.cs

示例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());
        }
开发者ID:billwaddyjr,项目名称:Razor,代码行数:23,代码来源:TagHelperExecutionContextTest.cs

示例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);
        }
开发者ID:leloulight,项目名称:Razor,代码行数:25,代码来源:TagHelperExecutionContextTest.cs

示例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()));
        }
开发者ID:leloulight,项目名称:Razor,代码行数:25,代码来源:TagHelperExecutionContextTest.cs

示例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));
        }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:36,代码来源:RazorPageTest.cs


注:本文中的Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。