Inheritance: RazorMail.Parsers.HtmlAgilityPackParser
Ejemplo n.º 1
0
        public void AppendBrToBlockElements_DoesAppendBrElementsToBlockElements()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body><h1>Heading</h1><div>This is a test</div>.</body></html>");

            // Act
            parser.TestAppendBrToBlockElements(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerHtml, Is.StringContaining("<br></h1>"));
            Assert.That(Html.DocumentNode.InnerHtml, Is.StringContaining("<br></div>"));
        }
Ejemplo n.º 2
0
        public void AppendTableDividers_DoesInsertTableCellDividers()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body><table><tr><th>Column 1:</th><th>Column 2</th></tr><tr><td>Row 1-A:</td><td>Row 1-B</td></tr><tr><td>Row 2-A</td><td>Row 2-B</td></tr></table></body></html>");

            // Act
            parser.TestAppendTableDividers(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerText, Is.StringContaining("Column 1: Column 2"));
            Assert.That(Html.DocumentNode.InnerText, Is.StringContaining("Row 1-A: Row 1-B"));
            Assert.That(Html.DocumentNode.InnerText, Is.StringContaining("Row 2-A, Row 2-B"));
        }
Ejemplo n.º 3
0
        public void RemoveUnwantedElements_DoesRemoveUnwantedElements()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><head><style>.test { margin: 5px; }</style></head><body><img src=\"test.jpg\" alt=\"test\" /><!-- this is a test comment --></body></html>");

            // Act
            parser.TestRemoveUnwantedElements(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerText, Is.Empty);
        }
Ejemplo n.º 4
0
        public void ReplaceHrefElements_WhenLinkTextIsAvailable_DoesReplaceHrefElementsWithTextAndUrl()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body>This is a test <a href=\"http://www.wduffy.co.uk\">link</a>.</body></html>");

            // Act
            parser.TestReplaceHrefElements(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerText, Is.StringContaining("This is a test link [ http://www.wduffy.co.uk ]."));
        }
Ejemplo n.º 5
0
        public void ReplaceHrefElements_WhenLinkIsImageWithNoAltTag_DoesReplaceHrefElementsWithUrl()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body>This is a test <a href=\"http://www.wduffy.co.uk\"><img src=\"test.jpg\" /></a> image link.</body></html>");

            // Act
            parser.TestReplaceHrefElements(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerText, Is.StringContaining("This is a test http://www.wduffy.co.uk image link."));
        }
Ejemplo n.º 6
0
        public void ReplaceHrefElements_WhenLinkIsEmailAddress_DoesReplaceHrefWithEmailAddressWithoutMailTo()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body>This is a test <a href=\"mailto:" + ObjectMother.TestAddress +"\">email address</a>.</body></html>");

            // Act
            parser.TestReplaceHrefElements(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerText, Is.StringContaining("This is a test email address [ " + ObjectMother.TestAddress + " ]."));
        }
Ejemplo n.º 7
0
        public void ReplaceBrElements_DoesReplaceBrElementsWithNewLines()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body>This<br />is<br /><br /><br />a<br />test.</body></html>");

            // Act
            parser.TestReplaceBrElements(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerHtml, Is.Not.StringContaining("<br />"));
        }
Ejemplo n.º 8
0
        public void RemoveWhiteSpace_DoesRemoveExcesswhiteSpace()
        {
            // Arrange
            var parser = new HtmlAgilityPackParserTester(Uri);
            Html.LoadHtml("<html><body>This     is a      test  with       whitespace   \r\n   \r\n\r\n    to       remove.</body></html>");

            // Act
            parser.TestRemoveWhitespace(Html.DocumentNode);

            // Assert
            Assert.That(Html.DocumentNode.InnerText, Is.EqualTo("This is a test with whitespace to remove."));
        }