Created
March 23, 2018 18:55
-
-
Save justinsaraceno/c5c00a4e185dbdcfa3e781cf0d3e4322 to your computer and use it in GitHub Desktop.
HTML Encode vs URL Encode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| namespace EncodingTests | |
| { | |
| [TestClass] | |
| public class EncodeTests | |
| { | |
| [TestMethod] | |
| public void HtmlTags_WhenHtmlEncoded_WillReturnHTMLEncodedOutput() | |
| { | |
| // arrange | |
| var htmlTagToEncode = "<html>"; | |
| var expectedResult = "<html>"; | |
| // 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