using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using PlanB.Html.Nodes; using PlanB.Html; namespace TestProject1 { [TestClass] public class ParseErrorTests { public ParseErrorTests() { // // TODO: Add constructor logic here // } private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes // // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion [TestMethod] public void Test_Parse_UnknownTag() { String htmlText = ""; String expectedResult = "<asdf></asdf>"; HtmlNode htmlNode = Parser.Parse(htmlText); Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null."); Assert.AreEqual(htmlNode.Children.Count, 1); Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode)); Assert.AreEqual(htmlNode.Children[0].Children.Count, 0); Assert.AreEqual(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnclosedTag() { String htmlText = "
asdffdsajkl;"; String expectedResult = "
asdffdsajkl;
"; HtmlNode htmlNode = Parser.Parse(htmlText); Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null."); Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlDivNode)); Assert.AreEqual(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnescapedAmpersand() { String htmlText = "hello&world"; String expectedResult = "hello&world"; HtmlNode htmlNode = Parser.Parse(htmlText); Assert.IsNotNull(htmlNode); Assert.AreEqual(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnescapedLessThan() { String htmlText = "hello(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnescapedLessThanThatLooksLikeATag() { String htmlText = "hello
(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnescapedGreaterThan() { String htmlText = "hello>world"; String expectedResult = "hello>world"; HtmlNode htmlNode = Parser.Parse(htmlText); Assert.IsNotNull(htmlNode); Assert.AreEqual(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnescapedQuote() { String htmlText = "hello\"world"; String expectedResult = "hello"world"; HtmlNode htmlNode = Parser.Parse(htmlText); Assert.IsNotNull(htmlNode); Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode)); Assert.AreEqual(expectedResult, htmlNode.InnerHtml); } [TestMethod] public void Test_Parse_UnopenedTag() { String htmlText = "
hello world
"; String expectedResult = "
hello world
"; HtmlNode htmlNode = Parser.Parse(htmlText); Assert.IsNotNull(htmlNode); Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlDivNode)); Assert.AreEqual(expectedResult, htmlNode.InnerHtml); } } }