public void Test_Analyze() { var pageLinkAnalyzer = new PageLinkAnalyzer(); var pageHtml = @"<html> <head> </head> <body> <div> <a href=""page1"">page1</a> <a href=""/page2"">page2</a> <a href=""http://www.kooboo.com"">outsidelink</a> <a href=""#"">emptyclick</a> </div> </body> </html>"; SiteDownloadContext siteDownloadContext = new SiteDownloadContext(null, new DownloadOptions() { SiteName = "Test_Analyze", Url = "localhost", Pages = 20, Deep = 1 }, null, null); PageDownloadContext pageDownloadContext = new PageDownloadContext(siteDownloadContext, new PageLevel("http://localhost", 1), pageHtml); pageLinkAnalyzer.Analyze(pageDownloadContext); Assert.AreEqual(2, siteDownloadContext.DownloadQueue.Count); }
public void Test_Analyze() { var httpClientMock = new Mock <IHttpClient>(); httpClientMock.Setup(it => it.DownloadString(It.IsAny <string>())) .Returns <string>((url) => { return("stylesheet"); }); var siteFileProviderMock = new Mock <ISiteFileProvider>(); Dictionary <string, string> styles = new Dictionary <string, string>(); siteFileProviderMock.Setup(it => it.AddFile(It.IsAny <Site>(), It.IsAny <string>(), It.IsAny <string>())) .Callback <Site, string, string>((site1, path, content) => { styles.Add(path, content); }); var styleSheetAnalyzer = new StyleSheetAnalyzer(httpClientMock.Object, siteFileProviderMock.Object); var pageHtml = @"<html> <head> <link rel=""Stylesheet"" href=""/style1.css"" type=""text/css"" /> <link rel=""Stylesheet"" href=""/style2"" type=""text/css"" /> </head> <body> </body> </html>"; SiteDownloadContext siteDownloadContext = new SiteDownloadContext(null, new DownloadOptions() { SiteName = "Test_Analyze", Url = "localhost", Pages = 20, Deep = 1 }, null, null); PageDownloadContext pageDownloadContext = new PageDownloadContext(siteDownloadContext, new PageLevel("http://localhost", 1), pageHtml); styleSheetAnalyzer.Analyze(pageDownloadContext); Assert.AreEqual(2, styles.Count()); Assert.AreEqual("stylesheet", styles["\\Styles\\style1.css"]); Assert.AreEqual("stylesheet", styles["\\Styles\\style2"]); }