Skip to content

Instantly share code, notes, and snippets.

@justinsaraceno
Created March 23, 2018 18:55
Show Gist options
  • Select an option

  • Save justinsaraceno/c5c00a4e185dbdcfa3e781cf0d3e4322 to your computer and use it in GitHub Desktop.

Select an option

Save justinsaraceno/c5c00a4e185dbdcfa3e781cf0d3e4322 to your computer and use it in GitHub Desktop.
HTML Encode vs URL Encode
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EncodingTests
{
[TestClass]
public class EncodeTests
{
[TestMethod]
public void HtmlTags_WhenHtmlEncoded_WillReturnHTMLEncodedOutput()
{
// arrange
var htmlTagToEncode = "<html>";
var expectedResult = "&lt;html&gt;";
// act
var htmlEncodedResult = System.Web.HttpUtility.HtmlEncode(htmlTagToEncode);
// assert
Assert.AreEqual(htmlEncodedResult, expectedResult);
}
[TestMethod]
public void HtmlTags_WhenUrlEncoded_WillReturnUrlEncodedOutput()
{
// arrange
var htmlTagToEncode = "<html>";
var expectedResult = "%3chtml%3e";
// act
var htmlEncodedResult = System.Web.HttpUtility.UrlEncode(htmlTagToEncode);
// assert
Assert.AreEqual(htmlEncodedResult, expectedResult);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment