本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.DefaultTagHelperContent.GetContent方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultTagHelperContent.GetContent方法的具体用法?C# DefaultTagHelperContent.GetContent怎么用?C# DefaultTagHelperContent.GetContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.Razor.Runtime.TagHelpers.DefaultTagHelperContent
的用法示例。
在下文中一共展示了DefaultTagHelperContent.GetContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanSetContent
public void CanSetContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "HtmlEncode[[Hello World!]]";
// Act
tagHelperContent.SetContent("Hello World!");
// Assert
Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder()));
}
示例2: CanSetContent
public void CanSetContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "Hello World!";
// Act
tagHelperContent.SetContent(expected);
// Assert
Assert.Equal(expected, tagHelperContent.GetContent());
}
示例3: SetContent_WithTagHelperContent_WorksAsExpected
public void SetContent_WithTagHelperContent_WorksAsExpected(string expected)
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var copiedTagHelperContent = new DefaultTagHelperContent();
tagHelperContent.SetContent(expected);
// Act
copiedTagHelperContent.SetContent(tagHelperContent);
// Assert
Assert.Equal(expected, copiedTagHelperContent.GetContent());
}
示例4: SetContentClearsExistingContent
public void SetContentClearsExistingContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "Hello World!";
tagHelperContent.SetContent("Contoso");
// Act
tagHelperContent.SetContent(expected);
// Assert
Assert.Equal(expected, tagHelperContent.GetContent());
}
示例5: CanAppendFormat_WithDifferentCurrentCulture
public void CanAppendFormat_WithDifferentCurrentCulture()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.AppendFormat(CultureInfo.CurrentCulture, "{0:D}", DateTime.Parse("01/02/2015"));
// Assert
Assert.Equal("01 February 2015", tagHelperContent.GetContent());
}
示例6: CanAppendDefaultTagHelperContent
public void CanAppendDefaultTagHelperContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var helloWorldContent = new DefaultTagHelperContent();
helloWorldContent.SetContent("HelloWorld");
var expected = "Content was HelloWorld";
// Act
tagHelperContent.AppendFormat("Content was {0}", helloWorldContent);
// Assert
Assert.Equal(expected, tagHelperContent.GetContent());
}
示例7: CanAppendFormat_WithCulture_3Arguments
public void CanAppendFormat_WithCulture_3Arguments()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.AppendFormat(
CultureInfo.InvariantCulture,
"Numbers in InvariantCulture - {0, -5:N} {1} {2}!",
1.1,
2.98,
3.12);
// Assert
Assert.Equal("Numbers in InvariantCulture - 1.10 2.98 3.12!", tagHelperContent.GetContent());
}
示例8: CanAppendFormat_WithDifferentCulture
public void CanAppendFormat_WithDifferentCulture()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var culture = new CultureInfo("fr-FR");
// Act
tagHelperContent.AppendFormat(culture, "{0} in french!", 1.21);
// Assert
Assert.Equal("1,21 in french!", tagHelperContent.GetContent());
}
示例9: CanAppendFormat_WithCulture
public void CanAppendFormat_WithCulture()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.AppendFormat(
CultureInfo.InvariantCulture,
"Numbers in InvariantCulture - {0:N} {1} {2} {3}!",
1.1,
2.98,
145.82,
32.86);
// Assert
Assert.Equal(
"Numbers in InvariantCulture - HtmlEncode[[1.10]] HtmlEncode[[2.98]] " +
"HtmlEncode[[145.82]] HtmlEncode[[32.86]]!",
tagHelperContent.GetContent(new CommonTestEncoder()));
}
示例10: CanAppendFormat_WithCulture
public void CanAppendFormat_WithCulture()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.AppendFormat(
CultureInfo.InvariantCulture,
"Numbers in InvariantCulture - {0, -5:N} {1} {2} {3}!",
1.1,
2.98,
145.82,
32.86);
// Assert
Assert.Equal("Numbers in InvariantCulture - 1.10 2.98 145.82 32.86!", tagHelperContent.GetContent());
}
示例11: Fluent_Clear_Set_Append_WritesExpectedContent
public void Fluent_Clear_Set_Append_WritesExpectedContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "Hello World!";
tagHelperContent.SetContent("Some Random Content");
// Act
tagHelperContent.Clear().SetContent("Hello ").Append("World!");
// Assert
Assert.Equal(expected, tagHelperContent.GetContent());
}
示例12: ProcessAsync_FlowsEntryLinkThatAllowsAddingTriggersToAddedEntry
public async Task ProcessAsync_FlowsEntryLinkThatAllowsAddingTriggersToAddedEntry()
{
// Arrange
var id = "some-id";
var expectedContent = new DefaultTagHelperContent();
expectedContent.SetContent("some-content");
var tokenSource = new CancellationTokenSource();
var cache = new MemoryCache(new MemoryCacheOptions());
var cacheEntryOptions = new MemoryCacheEntryOptions()
.AddExpirationTrigger(new CancellationTokenTrigger(tokenSource.Token));
var tagHelperContext = new TagHelperContext(
allAttributes: new TagHelperAttributeList(),
items: new Dictionary<object, object>(),
uniqueId: id,
getChildContentAsync: () =>
{
TagHelperContent tagHelperContent;
if(!cache.TryGetValue("key1", out tagHelperContent))
{
tagHelperContent = expectedContent;
cache.Set("key1", tagHelperContent, cacheEntryOptions);
}
return Task.FromResult(tagHelperContent);
});
var tagHelperOutput = new TagHelperOutput("cache", new TagHelperAttributeList { { "attr", "value" } });
tagHelperOutput.PreContent.SetContent("<cache>");
tagHelperOutput.PostContent.SetContent("</cache>");
var cacheTagHelper = new CacheTagHelper(cache)
{
ViewContext = GetViewContext(),
};
var key = cacheTagHelper.GenerateKey(tagHelperContext);
// Act - 1
await cacheTagHelper.ProcessAsync(tagHelperContext, tagHelperOutput);
TagHelperContent cachedValue;
var result = cache.TryGetValue(key, out cachedValue);
// Assert - 1
Assert.Equal(expectedContent.GetContent(), tagHelperOutput.Content.GetContent());
Assert.True(result);
Assert.Equal(expectedContent, cachedValue);
// Act - 2
tokenSource.Cancel();
result = cache.TryGetValue(key, out cachedValue);
// Assert - 2
Assert.False(result);
Assert.Null(cachedValue);
}
示例13: CanAppendFormatContent
public void CanAppendFormatContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.AppendFormat("{0} {1} {2} {3}!", "First", "Second", "Third", "Fourth");
// Assert
Assert.Equal(
"HtmlEncode[[First]] HtmlEncode[[Second]] HtmlEncode[[Third]] HtmlEncode[[Fourth]]!",
tagHelperContent.GetContent(new CommonTestEncoder()));
}
示例14: CanAppendFormatContent_With3Arguments
public void CanAppendFormatContent_With3Arguments()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.AppendFormat("0x{0, -5:X} - {1} equivalent for {2}.", 50, "hex", 50);
// Assert
Assert.Equal("0x32 - hex equivalent for 50.", tagHelperContent.GetContent());
}
示例15: Fluent_Clear_SetContent_WritesExpectedContent
public void Fluent_Clear_SetContent_WritesExpectedContent()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
var expected = "HtmlEncode[[Hello World]]";
tagHelperContent.SetContent("Some Random Content");
// Act
tagHelperContent.Clear().SetContent("Hello World");
// Assert
Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder()));
}