public void can_process_links_from_this_orgin() { _pageElementProcessor = new ATagLinksProcessor(_resourceFactoryMock.Object, _relativaPathProducerMock.Object, _resourceStackMock.Object, 1, InitialHostUri, false); string testPage = @"<html><head> </head> <body> <a href=""http://www.example.com/blog.html""> <a href=""http://www.notexample.com/about/contacts""> </body> </html>"; HtmlDocument document = new HtmlDocument(); document.LoadHtml(testPage); _relativaPathProducerMock.Setup( x => x.GetRelativePath(It.Is<Uri>(d => d == InitialHostUri), It.Is<Uri>(d => d == new Uri("http://www.example.com/blog.html")))).Returns("blog.html"); var resultDocument = _pageElementProcessor.ProcessPage(document, InitialHostUri); Assert.That(resultDocument.DocumentNode.InnerHtml.Contains("href=\"blog.html\"")); Assert.That(resultDocument.DocumentNode.InnerHtml.Contains("http://www.notexample.com/about/contacts")); _resourceFactoryMock.Verify(x => x.GetHtmlModel(It.IsAny<Uri>(), 0), Times.Exactly(1)); _relativaPathProducerMock.Verify(x => x.GetRelativePath(It.Is<Uri>(d => d == InitialHostUri), It.IsAny<Uri>()), Times.Exactly(1)); _resourceStackMock.Verify(x => x.AddResourceToQueue(It.IsAny<PageResource>()), Times.Exactly(1)); }
public void should_change_only_already_processed_if_deep_equals_zero() { _pageElementProcessor = new ATagLinksProcessor(_resourceFactoryMock.Object, _relativaPathProducerMock.Object, _resourceStackMock.Object, 0, InitialHostUri, true); string testPage = @"<html><head> </head> <body> <a href=""http://www.example.com/blog.html""> <a href=""http://www.notexample.com/about/contacts""> </body> </html>"; HtmlDocument document = new HtmlDocument(); document.LoadHtml(testPage); _resourceStackMock.Setup(x => x.WasNotProcessed(new Uri("http://www.notexample.com/about/contacts"))) .Returns(false); _relativaPathProducerMock.Setup( x => x.GetRelativePath(It.Is<Uri>(d => d == InitialHostUri), It.Is<Uri>(d => d == new Uri("http://www.notexample.com/about/contacts")))).Returns("..\\www.notexample.com\\about\\contacts.html"); var resultDocument = _pageElementProcessor.ProcessPage(document, InitialHostUri); Assert.That(resultDocument.DocumentNode.InnerHtml.Contains("href=\"http://www.example.com/blog.html\"")); Assert.That(resultDocument.DocumentNode.InnerHtml.Contains("href=\"..\\www.notexample.com\\about\\contacts.html")); _resourceFactoryMock.Verify(x => x.GetHtmlModel(It.IsAny<Uri>(), 0), Times.Never()); _relativaPathProducerMock.Verify(x => x.GetRelativePath(It.Is<Uri>(d => d == InitialHostUri), It.IsAny<Uri>()), Times.Exactly(2)); _resourceStackMock.Verify(x => x.AddResourceToQueue(It.IsAny<PageResource>()), Times.Exactly(0)); }