public void SetHtmlContent_TextIsNotFurtherEncoded() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); // Act tagHelperContent.SetHtmlContent("Hi"); // Assert Assert.Equal("Hi", tagHelperContent.GetContent(new CommonTestEncoder())); }
public void SetHtmlContent_TextIsNotFurtherEncoded() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); // Act tagHelperContent.SetHtmlContent("Hi"); // Assert Assert.Equal("Hi", tagHelperContent.GetContent(new HtmlTestEncoder())); }
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())); }
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())); }
public void Fluent_SetContent_Append_WritesExpectedContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "HtmlEncode[[Hello ]]HtmlEncode[[World!]]"; // Act tagHelperContent.SetContent("Hello ").Append("World!"); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder())); }
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 HtmlTestEncoder())); }
public void Fluent_SetContent_AppendFormat_WritesExpectedContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "HtmlEncode[[First ]]HtmlEncode[[Second]] Third"; // Act tagHelperContent.SetContent("First ").AppendFormat("{0} Third", "Second"); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder())); }
public void SetContent_WithTagHelperContent_WorksAsExpected(string content, string expected) { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var copiedTagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent(content); // Act copiedTagHelperContent.SetContent(tagHelperContent); // Assert Assert.Equal(expected, copiedTagHelperContent.GetContent(new HtmlTestEncoder())); }
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 CommonTestEncoder())); }
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())); }
public void SetContentClearsExistingContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "HtmlEncode[[Hello World!]]"; tagHelperContent.SetContent("Contoso"); // Act tagHelperContent.SetContent("Hello World!"); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder())); }
public void CanGetContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "Hello World!"; tagHelperContent.SetContent(expected); // Act var actual = tagHelperContent.GetContent(); // Assert Assert.Equal(expected, actual); }
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())); }
public void SetContent_WithTagHelperContent_WorksAsExpected(string content, string expected) { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var copiedTagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetContent(content); // Act copiedTagHelperContent.SetContent(tagHelperContent); // Assert Assert.Equal(expected, copiedTagHelperContent.GetContent(new CommonTestEncoder())); }
public void CanAppendDefaultTagHelperContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var helloWorldContent = new DefaultTagHelperContent(); helloWorldContent.SetContent("HelloWorld"); var expected = "Content was HtmlEncode[[HelloWorld]]"; // Act tagHelperContent.AppendFormat("Content was {0}", helloWorldContent); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder())); }
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.Append(tagHelperContent); // Assert Assert.Equal(expected, copiedTagHelperContent.GetContent(new CommonTestEncoder())); }
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())); }
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())); }
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 HtmlTestEncoder())); }
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 HtmlTestEncoder())); }
public void CanAppendDefaultTagHelperContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var helloWorldContent = new DefaultTagHelperContent(); helloWorldContent.SetContent("HelloWorld"); var expected = "Content was HtmlEncode[[HelloWorld]]"; // Act tagHelperContent.AppendFormat("Content was {0}", helloWorldContent); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new HtmlTestEncoder())); }
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())); }
public void Fluent_Clear_Set_Append_WritesExpectedContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "HtmlEncode[[Hello ]]HtmlEncode[[World!]]"; tagHelperContent.SetContent("Some Random Content"); // Act tagHelperContent.Clear().SetContent("Hello ").Append("World!"); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new HtmlTestEncoder())); }
public void Fluent_SetContent_AppendFormat_Append_WritesExpectedContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "HtmlEncode[[First ]]HtmlEncode[[Second]] Third HtmlEncode[[Fourth]]"; // Act tagHelperContent .SetContent("First ") .AppendFormat("{0} Third ", "Second") .Append("Fourth"); // Assert Assert.Equal(expected, tagHelperContent.GetContent(new HtmlTestEncoder())); }
public void CanGetContent() { // Arrange var tagHelperContent = new DefaultTagHelperContent(); var expected = "Hello World!"; tagHelperContent.SetContent(expected); // Act var actual = tagHelperContent.GetContent(); // Assert Assert.Equal(expected, actual); }
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() .AddExpirationToken(new CancellationChangeToken(tokenSource.Token)); var tagHelperContext = new TagHelperContext( allAttributes: new TagHelperAttributeList(), items: new Dictionary<object, object>(), uniqueId: id); var tagHelperOutput = new TagHelperOutput( "cache", new TagHelperAttributeList { { "attr", "value" } }, getChildContentAsync: useCachedResult => { TagHelperContent tagHelperContent; if (!cache.TryGetValue("key1", out tagHelperContent)) { tagHelperContent = expectedContent; cache.Set("key1", tagHelperContent, cacheEntryOptions); } return Task.FromResult(tagHelperContent); }); 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); }