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


C# DefaultTagHelperContent.SetHtmlContent方法代码示例

本文整理汇总了C#中Microsoft.AspNetCore.Razor.TagHelpers.DefaultTagHelperContent.SetHtmlContent方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultTagHelperContent.SetHtmlContent方法的具体用法?C# DefaultTagHelperContent.SetHtmlContent怎么用?C# DefaultTagHelperContent.SetHtmlContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNetCore.Razor.TagHelpers.DefaultTagHelperContent的用法示例。


在下文中一共展示了DefaultTagHelperContent.SetHtmlContent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetHtmlContent_TextIsNotFurtherEncoded

        public void SetHtmlContent_TextIsNotFurtherEncoded()
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();

            // Act
            tagHelperContent.SetHtmlContent("Hi");

            // Assert
            Assert.Equal("Hi", tagHelperContent.GetContent(new HtmlTestEncoder()));
        }
开发者ID:x-strong,项目名称:Razor,代码行数:11,代码来源:DefaultTagHelperContentTest.cs

示例2: SetHtmlContent_ClearsExistingContent

        public void SetHtmlContent_ClearsExistingContent()
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();
            tagHelperContent.AppendHtml("Contoso");

            // Act
            tagHelperContent.SetHtmlContent("Hello World!");

            // Assert
            Assert.Equal("Hello World!", tagHelperContent.GetContent(new HtmlTestEncoder()));
        }
开发者ID:x-strong,项目名称:Razor,代码行数:12,代码来源:DefaultTagHelperContentTest.cs

示例3: SetHtmlContent_WithTagHelperContent_WorksAsExpected

        public void SetHtmlContent_WithTagHelperContent_WorksAsExpected(string content, string expected)
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();
            var copiedTagHelperContent = new DefaultTagHelperContent();
            tagHelperContent.SetContent(content);

            // Act
            copiedTagHelperContent.SetHtmlContent(tagHelperContent);

            // Assert
            Assert.Equal(expected, copiedTagHelperContent.GetContent(new HtmlTestEncoder()));
        }
开发者ID:x-strong,项目名称:Razor,代码行数:13,代码来源:DefaultTagHelperContentTest.cs

示例4: GetTagHelperOutput

        private static TagHelperOutput GetTagHelperOutput(
            string tagName = "distributed-cache",
            TagHelperAttributeList attributes = null,
            string childContent = "some child content")
        {
            attributes = attributes ?? new TagHelperAttributeList { { "attr", "value" } };

            return new TagHelperOutput(
                tagName,
                attributes,
                getChildContentAsync: (useCachedResult, encoder) =>
                {
                    var tagHelperContent = new DefaultTagHelperContent();
                    tagHelperContent.SetHtmlContent(childContent);
                    return Task.FromResult<TagHelperContent>(tagHelperContent);
                });
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:17,代码来源:DistributedCacheTagHelperTest.cs

示例5: ProcessAsync_ExceptionInProcessing_DoesntBlockConcurrentRequests

        public async Task ProcessAsync_ExceptionInProcessing_DoesntBlockConcurrentRequests()
        {
            // Arrange
            var childContent = "some-content";
            var resetEvent1 = new ManualResetEvent(false);
            var resetEvent2 = new ManualResetEvent(false);
            var resetEvent3 = new ManualResetEvent(false);
            var calls = 0;
            var formatter = GetFormatter();
            var storage = GetStorage();
            var service = new DistributedCacheTagHelperService(
                storage,
                formatter,
                new HtmlTestEncoder(),
                NullLoggerFactory.Instance
                );
            var tagHelperContext1 = GetTagHelperContext();
            var tagHelperContext2 = GetTagHelperContext();

            var tagHelperOutput1 = new TagHelperOutput(
                "distributed-cache",
                new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
                {
                    calls++;
                    resetEvent2.Set();

                    throw new Exception();
                });

            var tagHelperOutput2 = new TagHelperOutput(
                "distributed-cache",
                new TagHelperAttributeList(),
                getChildContentAsync: (useCachedResult, encoder) =>
                {
                    calls++;
                    resetEvent3.WaitOne(5000);

                    var tagHelperContent = new DefaultTagHelperContent();
                    tagHelperContent.SetHtmlContent(childContent);
                    return Task.FromResult<TagHelperContent>(tagHelperContent);
                });

            var cacheTagHelper1 = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ViewContext = GetViewContext(),
                Enabled = true
            };

            var cacheTagHelper2 = new DistributedCacheTagHelper(
                service,
                new HtmlTestEncoder())
            {
                ViewContext = GetViewContext(),
                Enabled = true
            };

            // Act

            var task1 = Task.Run(async () =>
            {
                resetEvent1.WaitOne(5000);
                await Assert.ThrowsAsync<Exception>(() => cacheTagHelper1.ProcessAsync(tagHelperContext1, tagHelperOutput1));
                resetEvent3.Set();
            });

            var task2 = Task.Run(async () =>
            {
                resetEvent2.WaitOne(5000);
                await cacheTagHelper2.ProcessAsync(tagHelperContext2, tagHelperOutput2);
            });

            resetEvent1.Set();
            await Task.WhenAll(task1, task2);

            // Assert
            Assert.Empty(tagHelperOutput1.PreContent.GetContent());
            Assert.Empty(tagHelperOutput1.PostContent.GetContent());
            Assert.False(tagHelperOutput1.IsContentModified);
            Assert.Empty(tagHelperOutput1.Content.GetContent());

            Assert.Empty(tagHelperOutput2.PreContent.GetContent());
            Assert.Empty(tagHelperOutput2.PostContent.GetContent());
            Assert.True(tagHelperOutput2.IsContentModified);
            Assert.Equal(childContent, tagHelperOutput2.Content.GetContent());

            Assert.Equal(2, calls);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:90,代码来源:DistributedCacheTagHelperTest.cs


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