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


C# DefaultTagHelperContent.Append方法代码示例

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


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

示例1: IsEmptyOrWhiteSpace_FalseAfterAppend

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

            // Act
            tagHelperContent.Append("Hello");

            // Assert
            Assert.False(tagHelperContent.IsEmptyOrWhiteSpace);
        }
开发者ID:x-strong,项目名称:Razor,代码行数:11,代码来源:DefaultTagHelperContentTest.cs

示例2: CanIdentifyWhiteSpace_WithoutIgnoringStrings

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

            // Act
            tagHelperContent.SetContent("  ");
            tagHelperContent.Append("Hello");

            // Assert
            Assert.True(tagHelperContent.GetContent().Length > 0);
            Assert.False(tagHelperContent.IsEmptyOrWhiteSpace);
        }
开发者ID:x-strong,项目名称:Razor,代码行数:13,代码来源:DefaultTagHelperContentTest.cs

示例3: IsEmptyOrWhiteSpace_TrueAfterAppendEmptyTagHelperContent

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

            // Act
            tagHelperContent.AppendHtml(copiedTagHelperContent);
            tagHelperContent.Append(string.Empty);

            // Assert
            Assert.True(tagHelperContent.IsEmptyOrWhiteSpace);
        }
开发者ID:x-strong,项目名称:Razor,代码行数:13,代码来源:DefaultTagHelperContentTest.cs

示例4: IsModified_TrueAfterAppend

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

            // Act
            tagHelperContent.Append(string.Empty);

            // Assert
            Assert.True(tagHelperContent.IsModified);
        }
开发者ID:x-strong,项目名称:Razor,代码行数:11,代码来源:DefaultTagHelperContentTest.cs

示例5: CanIdentifyEmptyOrWhiteSpace

        public void CanIdentifyEmptyOrWhiteSpace(string data)
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();

            // Act
            tagHelperContent.SetContent("  ");
            tagHelperContent.Append(data);

            // Assert
            Assert.True(tagHelperContent.IsEmptyOrWhiteSpace);
        }
开发者ID:x-strong,项目名称:Razor,代码行数:12,代码来源:DefaultTagHelperContentTest.cs

示例6: IsEmptyOrWhiteSpace_TrueAfterAppendTwice

        public void IsEmptyOrWhiteSpace_TrueAfterAppendTwice(string data)
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();

            // Act
            tagHelperContent.Append(data);
            tagHelperContent.Append(data);

            // Assert
            Assert.True(tagHelperContent.IsEmptyOrWhiteSpace);
        }
开发者ID:cjqian,项目名称:Razor,代码行数:12,代码来源:DefaultTagHelperContentTest.cs

示例7: Append_WithTagHelperContent_MultipleAppends

        public void Append_WithTagHelperContent_MultipleAppends()
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();
            var copiedTagHelperContent = new DefaultTagHelperContent();
            var text1 = "Hello";
            var text2 = " World!";
            var expected = "HtmlEncode[[Hello]]HtmlEncode[[ World!]]";
            tagHelperContent.Append(text1);
            tagHelperContent.Append(text2);

            // Act
            copiedTagHelperContent.AppendHtml(tagHelperContent);

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

示例8: CopyTo_CopiesAllItems

        public void CopyTo_CopiesAllItems()
        {
            // Arrange
            var source = new DefaultTagHelperContent();
            source.AppendHtml(new HtmlEncodedString("hello"));
            source.Append("Test");

            var items = new List<object>();
            var destination = new HtmlContentBuilder(items);
            destination.Append("some-content");

            // Act
            source.CopyTo(destination);

            // Assert
            Assert.Equal(3, items.Count);

            Assert.Equal("some-content", Assert.IsType<string>(items[0]));
            Assert.Equal("hello", Assert.IsType<HtmlEncodedString>(items[1]).Value);
            Assert.Equal("Test", Assert.IsType<string>(items[2]));
        }
开发者ID:x-strong,项目名称:Razor,代码行数:21,代码来源:DefaultTagHelperContentTest.cs

示例9: MoveTo_DoesDeepMove

        public void MoveTo_DoesDeepMove()
        {
            // Arrange
            var source = new DefaultTagHelperContent();

            var nested = new DefaultTagHelperContent();
            source.AppendHtml(nested);
            nested.AppendHtml(new HtmlEncodedString("hello"));
            source.Append("Test");

            var items = new List<object>();
            var destination = new HtmlContentBuilder(items);
            destination.Append("some-content");

            // Act
            source.MoveTo(destination);

            // Assert
            Assert.Equal(string.Empty, source.GetContent());
            Assert.Equal(string.Empty, nested.GetContent());
            Assert.Equal(3, items.Count);

            Assert.Equal("some-content", Assert.IsType<string>(items[0]));
            Assert.Equal("hello", Assert.IsType<HtmlEncodedString>(items[1]).Value);
            Assert.Equal("Test", Assert.IsType<string>(items[2]));
        }
开发者ID:x-strong,项目名称:Razor,代码行数:26,代码来源:DefaultTagHelperContentTest.cs

示例10: RendersLinkTagsForGlobbedHrefResults_EncodesAsExpected

        public void RendersLinkTagsForGlobbedHrefResults_EncodesAsExpected()
        {
            // Arrange
            var expectedContent =
                "<link encoded='contains \"quotes\"' href=\"HtmlEncode[[/css/site.css]]\" " +
                "literal=\"HtmlEncode[[all HTML encoded]]\" " +
                "mixed='HtmlEncode[[HTML encoded]] and contains \"quotes\"' />" +
                "<link encoded='contains \"quotes\"' href=\"HtmlEncode[[/base.css]]\" " +
                "literal=\"HtmlEncode[[all HTML encoded]]\" " +
                "mixed='HtmlEncode[[HTML encoded]] and contains \"quotes\"' />";
            var mixed = new DefaultTagHelperContent();
            mixed.Append("HTML encoded");
            mixed.AppendHtml(" and contains \"quotes\"");
            var context = MakeTagHelperContext(
                attributes: new TagHelperAttributeList
                {
                    { "asp-href-include", "**/*.css" },
                    { new TagHelperAttribute("encoded", new HtmlString("contains \"quotes\""), HtmlAttributeValueStyle.SingleQuotes) },
                    { "href", "/css/site.css" },
                    { "literal", "all HTML encoded" },
                    { new TagHelperAttribute("mixed", mixed, HtmlAttributeValueStyle.SingleQuotes) },
                });
            var output = MakeTagHelperOutput(
                "link",
                attributes: new TagHelperAttributeList
                {
                    { new TagHelperAttribute("encoded", new HtmlString("contains \"quotes\""), HtmlAttributeValueStyle.SingleQuotes) },
                    { "literal", "all HTML encoded" },
                    { new TagHelperAttribute("mixed", mixed, HtmlAttributeValueStyle.SingleQuotes) },
                });
            var hostingEnvironment = MakeHostingEnvironment();
            var viewContext = MakeViewContext();
            var globbingUrlBuilder = new Mock<GlobbingUrlBuilder>(
                new TestFileProvider(),
                Mock.Of<IMemoryCache>(),
                PathString.Empty);
            globbingUrlBuilder.Setup(g => g.BuildUrlList(null, "**/*.css", null))
                .Returns(new[] { "/base.css" });

            var helper = new LinkTagHelper(
                hostingEnvironment,
                MakeCache(),
                new HtmlTestEncoder(),
                new JavaScriptTestEncoder(),
                MakeUrlHelperFactory())
            {
                GlobbingUrlBuilder = globbingUrlBuilder.Object,
                Href = "/css/site.css",
                HrefInclude = "**/*.css",
                ViewContext = viewContext,
            };

            // Act
            helper.Process(context, output);

            // Assert
            Assert.Equal("link", output.TagName);
            Assert.Equal("/css/site.css", output.Attributes["href"].Value);
            var content = HtmlContentUtilities.HtmlContentToString(output, new HtmlTestEncoder());
            Assert.Equal(expectedContent, content);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:61,代码来源:LinkTagHelperTest.cs

示例11: RenderLinkTags_FallbackHref_WithFileVersion_EncodesAsExpected

        public void RenderLinkTags_FallbackHref_WithFileVersion_EncodesAsExpected()
        {
            // Arrange
            var expectedContent = "<link encoded=\"contains \"quotes\"\" " +
                "href=\"HtmlEncode[[/css/site.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk]]\" " +
                "literal=\"HtmlEncode[[all HTML encoded]]\" " +
                "mixed=\"HtmlEncode[[HTML encoded]] and contains \"quotes\"\" />" +
                Environment.NewLine +
                "<meta name=\"x-stylesheet-fallback-test\" content=\"\" class=\"HtmlEncode[[hidden]]\" />" +
                "<script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName(\"SCRIPT\")," +
                "g=f[f.length-1].previousElementSibling," +
                "h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;" +
                "if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel=\"stylesheet\" href=\"'+c[d]+'\"/>')}(" +
                "\"JavaScriptEncode[[visibility]]\",\"JavaScriptEncode[[hidden]]\"," +
                "[\"JavaScriptEncode[[HtmlEncode[[/fallback.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk]]]]\"]);" +
                "</script>";
            var mixed = new DefaultTagHelperContent();
            mixed.Append("HTML encoded");
            mixed.AppendHtml(" and contains \"quotes\"");
            var context = MakeTagHelperContext(
                attributes: new TagHelperAttributeList
                {
                    { "asp-append-version", "true" },
                    { "asp-fallback-href-include", "**/fallback.css" },
                    { "asp-fallback-test-class", "hidden" },
                    { "asp-fallback-test-property", "visibility" },
                    { "asp-fallback-test-value", "hidden" },
                    { "encoded", new HtmlString("contains \"quotes\"") },
                    { "href", "/css/site.css" },
                    { "literal", "all HTML encoded" },
                    { "mixed", mixed },
                });
            var output = MakeTagHelperOutput(
                "link",
                attributes: new TagHelperAttributeList
                {
                    { "encoded", new HtmlString("contains \"quotes\"") },
                    { "literal", "all HTML encoded" },
                    { "mixed", mixed },
                });
            var hostingEnvironment = MakeHostingEnvironment();
            var viewContext = MakeViewContext();
            var globbingUrlBuilder = new Mock<GlobbingUrlBuilder>(
                new TestFileProvider(),
                Mock.Of<IMemoryCache>(),
                PathString.Empty);
            globbingUrlBuilder.Setup(g => g.BuildUrlList(null, "**/fallback.css", null))
                .Returns(new[] { "/fallback.css" });

            var helper = new LinkTagHelper(
                MakeHostingEnvironment(),
                MakeCache(),
                new HtmlTestEncoder(),
                new JavaScriptTestEncoder(),
                MakeUrlHelperFactory())
            {
                AppendVersion = true,
                FallbackHrefInclude = "**/fallback.css",
                FallbackTestClass = "hidden",
                FallbackTestProperty = "visibility",
                FallbackTestValue = "hidden",
                GlobbingUrlBuilder = globbingUrlBuilder.Object,
                Href = "/css/site.css",
                ViewContext = viewContext,
            };

            // Act
            helper.Process(context, output);

            // Assert
            Assert.Equal("link", output.TagName);
            Assert.Equal("/css/site.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["href"].Value);
            var content = HtmlContentUtilities.HtmlContentToString(output, new HtmlTestEncoder());
            Assert.Equal(expectedContent, content);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:75,代码来源:LinkTagHelperTest.cs

示例12: GenerateMessageContent

		/// <summary>
		///     Generate the HTML content for a <see cref="OperationMessage" />.
		/// </summary>
		/// <param name="message">The <see cref="OperationMessage" /> instance.</param>
		/// <param name="useTwoLineMode">If the two line mode should be used.</param>
		/// <returns>The generated HTML content.</returns>
		private static IHtmlContent GenerateMessageContent(OperationMessage message, bool useTwoLineMode)
		{
			var result = new DefaultTagHelperContent();

			// Title
			result.AppendHtml(GenerateTitle(message.Title));

			// If description exists, add it
			if (!string.IsNullOrEmpty(message.Description))
			{
				// Add a newline for two line mode.
				if (useTwoLineMode)
				{
					// TODO: Consider a better way
					result.Append("<br />");
				}

				result.AppendHtml(GenerateDescrption(message.Description));
			}

			return result;
		}
开发者ID:sgjsakura,项目名称:AspNetCore,代码行数:28,代码来源:DefaultOperationMessageHtmlGenerator.cs

示例13: RenderScriptTags_FallbackSrc_WithFileVersion_EncodesAsExpected

        public void RenderScriptTags_FallbackSrc_WithFileVersion_EncodesAsExpected()
        {
            // Arrange
            var expectedContent =
                "<script encoded='contains \"quotes\"' literal=\"HtmlEncode[[all HTML encoded]]\" " +
                "mixed='HtmlEncode[[HTML encoded]] and contains \"quotes\"' " +
                "src=\"HtmlEncode[[/js/site.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk]]\"></script>" +
                Environment.NewLine +
                "<script>(isavailable()||document.write(\"JavaScriptEncode[[<script encoded=\'contains \"quotes\"\' " +
                "literal=\"HtmlEncode[[all HTML encoded]]\" mixed=\'HtmlEncode[[HTML encoded]] and contains " +
                "\"quotes\"' src=\"HtmlEncode[[fallback.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk]]\">" +
                "</script>]]\"));</script>";
            var mixed = new DefaultTagHelperContent();
            mixed.Append("HTML encoded");
            mixed.AppendHtml(" and contains \"quotes\"");
            var context = MakeTagHelperContext(
                attributes: new TagHelperAttributeList
                {
                    { "asp-append-version", "true" },
                    { "asp-fallback-src-include", "fallback.js" },
                    { "asp-fallback-test", "isavailable()" },
                    { new TagHelperAttribute("encoded", new HtmlString("contains \"quotes\""), HtmlAttributeValueStyle.SingleQuotes) },
                    { "literal", "all HTML encoded" },
                    { new TagHelperAttribute("mixed", mixed, HtmlAttributeValueStyle.SingleQuotes) },
                    { "src", "/js/site.js" },
                });
            var output = MakeTagHelperOutput(
                "script",
                attributes: new TagHelperAttributeList
                {
                    { new TagHelperAttribute("encoded", new HtmlString("contains \"quotes\""), HtmlAttributeValueStyle.SingleQuotes) },
                    { "literal", "all HTML encoded" },
                    { new TagHelperAttribute("mixed", mixed, HtmlAttributeValueStyle.SingleQuotes) },
                });
            var hostingEnvironment = MakeHostingEnvironment();
            var viewContext = MakeViewContext();

            var helper = new ScriptTagHelper(
                MakeHostingEnvironment(),
                MakeCache(),
                new HtmlTestEncoder(),
                new JavaScriptTestEncoder(),
                MakeUrlHelperFactory())
            {
                AppendVersion = true,
                FallbackSrc = "fallback.js",
                FallbackTestExpression = "isavailable()",
                Src = "/js/site.js",
                ViewContext = viewContext,
            };

            // Act
            helper.Process(context, output);

            // Assert
            Assert.Equal("script", output.TagName);
            Assert.Equal("/js/site.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["src"].Value);
            var content = HtmlContentUtilities.HtmlContentToString(output, new HtmlTestEncoder());
            Assert.Equal(expectedContent, content);
        }
开发者ID:xuchrist,项目名称:Mvc,代码行数:60,代码来源:ScriptTagHelperTest.cs

示例14: IsEmptyOrWhiteSpace_TrueAfterAppendTagHelperContentTwice_WithDataToEncode

        public void IsEmptyOrWhiteSpace_TrueAfterAppendTagHelperContentTwice_WithDataToEncode(string data)
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();
            var copiedTagHelperContent = new DefaultTagHelperContent();
            copiedTagHelperContent.Append(data);

            // Act
            tagHelperContent.AppendHtml(copiedTagHelperContent);
            tagHelperContent.AppendHtml(copiedTagHelperContent);

            // Assert
            Assert.True(tagHelperContent.IsEmptyOrWhiteSpace);
        }
开发者ID:cjqian,项目名称:Razor,代码行数:14,代码来源:DefaultTagHelperContentTest.cs

示例15: WriteTo_WritesToATextWriter

        public void WriteTo_WritesToATextWriter()
        {
            // Arrange
            var tagHelperContent = new DefaultTagHelperContent();
            var writer = new StringWriter();
            tagHelperContent.SetContent("Hello ");
            tagHelperContent.Append("World");

            // Act
            tagHelperContent.WriteTo(writer, new HtmlTestEncoder());

            // Assert
            Assert.Equal("HtmlEncode[[Hello ]]HtmlEncode[[World]]", writer.ToString());
        }
开发者ID:x-strong,项目名称:Razor,代码行数:14,代码来源:DefaultTagHelperContentTest.cs


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