當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。