Ejemplo n.º 1
0
        public async void Download_ReturnsEmptyDocument()
        {
            HtmlDocument emptyDocument = new HtmlDocument();

            Mock <IWebClientService> webClientMock = new Mock <IWebClientService>();

            webClientMock.Setup(a => a.FromWebAsync(It.IsAny <string>())).ReturnsAsync(emptyDocument);

            DotnetCrawlerDownloader downloader = new DotnetCrawlerDownloader(webClientMock.Object);
            HtmlDocument            result     = await downloader.Download(It.IsAny <string>());

            result.Should().Be(emptyDocument);
            webClientMock.Verify(m => m.FromWebAsync(It.IsAny <string>()), Times.Exactly(1));
        }
Ejemplo n.º 2
0
        public async void Download_ReturnsHeadingText()
        {
            HtmlDocument emptyDocument = new HtmlDocument();

            string html = DummyHtml();

            HtmlDocument htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(html);

            Mock <IWebClientService> webClientMock = new Mock <IWebClientService>();

            webClientMock.Setup(a => a.FromWebAsync(It.IsAny <string>())).ReturnsAsync(htmlDocument);

            DotnetCrawlerDownloader downloader = new DotnetCrawlerDownloader(webClientMock.Object);
            HtmlDocument            result     = await downloader.Download(It.IsAny <string>());

            string headingText = result.DocumentNode.SelectSingleNode("//body/h1/text()").InnerText;

            headingText.Should().Be("First heading");
            webClientMock.Verify(m => m.FromWebAsync(It.IsAny <string>()), Times.Exactly(1));
        }