Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }