Rename `AppendEncoded()` to `AppendHtml()` and `SetContentEncoded()` to `SetHtmlContent()`

- aspnet/Mvc#3225, 2 of 3
- also correct parameter names
This commit is contained in:
Doug Bunting 2015-10-21 15:44:12 -07:00
parent 6a7082d89e
commit 117bbe7f65
3 changed files with 44 additions and 16 deletions

View File

@ -122,15 +122,16 @@ namespace Microsoft.AspNet.Razor.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent Append(string value) public override TagHelperContent Append(string unencoded)
{ {
Buffer.Append(value); Buffer.Append(unencoded);
return this; return this;
} }
public override TagHelperContent AppendEncoded(string value) /// <inheritdoc />
public override TagHelperContent AppendHtml(string encoded)
{ {
Buffer.AppendEncoded(value); Buffer.AppendHtml(encoded);
return this; return this;
} }

View File

@ -61,18 +61,18 @@ namespace Microsoft.AspNet.Razor.TagHelpers
/// as-provided and no further encoding will be performed. /// as-provided and no further encoding will be performed.
/// </param> /// </param>
/// <returns>A reference to this instance after the set operation has completed.</returns> /// <returns>A reference to this instance after the set operation has completed.</returns>
public TagHelperContent SetContentEncoded(string encoded) public TagHelperContent SetHtmlContent(string encoded)
{ {
HtmlContentBuilderExtensions.SetContentEncoded(this, encoded); HtmlContentBuilderExtensions.SetHtmlContent(this, encoded);
return this; return this;
} }
/// <summary> /// <summary>
/// Appends <paramref name="value"/> to the existing content. /// Appends <paramref name="unencoded"/> to the existing content.
/// </summary> /// </summary>
/// <param name="value">The <see cref="string"/> to be appended.</param> /// <param name="unencoded">The <see cref="string"/> to be appended.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns> /// <returns>A reference to this instance after the append operation has completed.</returns>
public abstract TagHelperContent Append(string value); public abstract TagHelperContent Append(string unencoded);
/// <summary> /// <summary>
/// Appends <paramref name="htmlContent"/> to the existing content. /// Appends <paramref name="htmlContent"/> to the existing content.
@ -82,12 +82,12 @@ namespace Microsoft.AspNet.Razor.TagHelpers
public abstract TagHelperContent Append(IHtmlContent htmlContent); public abstract TagHelperContent Append(IHtmlContent htmlContent);
/// <summary> /// <summary>
/// Appends <paramref name="value"/> to the existing content. <paramref name="value"/> is assumed /// Appends <paramref name="encoded"/> to the existing content. <paramref name="encoded"/> is assumed
/// to be an HTML encoded <see cref="string"/> and no further encoding will be performed. /// to be an HTML encoded <see cref="string"/> and no further encoding will be performed.
/// </summary> /// </summary>
/// <param name="value">The <see cref="string"/> to be appended.</param> /// <param name="encoded">The <see cref="string"/> to be appended.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns> /// <returns>A reference to this instance after the append operation has completed.</returns>
public abstract TagHelperContent AppendEncoded(string value); public abstract TagHelperContent AppendHtml(string encoded);
/// <summary> /// <summary>
/// Appends the specified <paramref name="format"/> to the existing content after /// Appends the specified <paramref name="format"/> to the existing content after
@ -157,9 +157,9 @@ namespace Microsoft.AspNet.Razor.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
IHtmlContentBuilder IHtmlContentBuilder.AppendEncoded(string encoded) IHtmlContentBuilder IHtmlContentBuilder.AppendHtml(string encoded)
{ {
return AppendEncoded(encoded); return AppendHtml(encoded);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -39,6 +39,33 @@ namespace Microsoft.AspNet.Razor.TagHelpers
Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder())); Assert.Equal(expected, tagHelperContent.GetContent(new CommonTestEncoder()));
} }
[Fact]
public void SetHtmlContent_TextIsNotFurtherEncoded()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
// Act
tagHelperContent.SetHtmlContent("Hi");
// Assert
Assert.Equal("Hi", tagHelperContent.GetContent(new CommonTestEncoder()));
}
[Fact]
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()));
}
[Theory] [Theory]
[InlineData("HelloWorld!", "HtmlEncode[[HelloWorld!]]")] [InlineData("HelloWorld!", "HtmlEncode[[HelloWorld!]]")]
[InlineData(" ", "HtmlEncode[[ ]]")] [InlineData(" ", "HtmlEncode[[ ]]")]
@ -473,11 +500,11 @@ namespace Microsoft.AspNet.Razor.TagHelpers
} }
[Fact] [Fact]
public void AppendEncoded_DoesNotGetEncoded() public void AppendHtml_DoesNotGetEncoded()
{ {
// Arrange // Arrange
var tagHelperContent = new DefaultTagHelperContent(); var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded("Hi"); tagHelperContent.AppendHtml("Hi");
var writer = new StringWriter(); var writer = new StringWriter();