public CrawlReport Crawl(Uri uri)
        {
            if (uri == null) throw new ArgumentNullException(nameof(uri));

            var crawler = new Crawler(new AbotCrawl(_log), _log, new AngleSharpExaminerFactory(), GetInspectors());
            return crawler.Crawl(uri);
        }
        public void CallCrawlStartingOnInspectorOnce()
        {
            // Arrange
            var inspector = new Mock<IInspector>();
            var crawler = new Crawler(new Mock<ICrawl>().Object, new Mock<ILogHandler>().Object, new Mock<IExaminerFactory>().Object, new [] { inspector.Object });

            // Act
            crawler.Crawl(_uri);

            // Assert
            inspector.Verify(x => x.CrawlStarting(), Times.Once);
        }
        public void LogWhenInspectorThrowExceptionAtInspectPage()
        {
            // Arrange
            var page = CreatePage();
            var exception = new Exception("Test exception");
            var inspector = new Mock<IInspector>();
            var crawl = _fixture.Freeze<Mock<ICrawl>>();
            var logHandler = new Mock<ILogHandler>();
            crawl.Setup(c => c.Crawl(_uri, It.IsAny<Action<Page>>())).Callback<Uri, Action<Page>>((uri, action) => action(page));
            inspector.Setup(i => i.InspectPage(page)).Throws(exception);
            var crawler = new Crawler(crawl.Object, logHandler.Object, new Mock<IExaminerFactory>().Object, new[] { inspector.Object });

            // Act
            crawler.Crawl(_uri);

            // Assert
            logHandler.Verify(x => x.Log(It.Is<InspectorLogMessage>(
                l => l.Inspector.Name == inspector.Object.Name &&
                l.LogMessage.LogType == LogType.Error &&
                l.LogMessage.Exception == exception)), Times.Once);
        }
        public void PassPageToInspectorOnce()
        {
            // Arrange
            var page = CreatePage();
            var inspector = new Mock<IInspector>();
            var crawl = _fixture.Freeze<Mock<ICrawl>>();
            crawl.Setup(c => c.Crawl(_uri, It.IsAny<Action<Page>>())).Callback<Uri, Action<Page>>((uri, action) => action(page));
            var crawler = new Crawler(crawl.Object, new Mock<ILogHandler>().Object, new Mock<IExaminerFactory>().Object, new[] { inspector.Object });

            // Act
            crawler.Crawl(_uri);

            // Assert
            inspector.Verify(i => i.InspectPage(page), Times.Once);
        }
        public void LogWhenInspectorThrowsExceptionAtCrawlStarting()
        {
            // Arrange
            var inspector = new Mock<IInspector>();
            var exception = new Exception("Test exception");
            inspector.Setup(i => i.CrawlStarting()).Throws(exception);
            var logHandler = new Mock<ILogHandler>();
            var crawler = new Crawler(new Mock<ICrawl>().Object, logHandler.Object, new Mock<IExaminerFactory>().Object, new[] { inspector.Object });

            // Act
            crawler.Crawl(_uri);

            // Assert
            logHandler.Verify(x => x.Log(It.Is<InspectorLogMessage>(
                l => l.Inspector.Name == inspector.Object.Name &&
                l.LogMessage.LogType == LogType.Error &&
                l.LogMessage.Exception == exception)), Times.Once);
        }