本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: IsModified_TrueAfterAppend
public void IsModified_TrueAfterAppend()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.Append(string.Empty);
// Assert
Assert.True(tagHelperContent.IsModified);
}
示例5: CanIdentifyEmptyOrWhiteSpace
public void CanIdentifyEmptyOrWhiteSpace(string data)
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.SetContent(" ");
tagHelperContent.Append(data);
// Assert
Assert.True(tagHelperContent.IsEmptyOrWhiteSpace);
}
示例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);
}
示例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()));
}
示例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]));
}
示例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]));
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}