Exemplo n.º 1
0
        public void CrawleOnePage()
        {
            //arrange
            var loader = new Mock<IHtmlDocumentLoader>();
            var context = new Mock<ICrawlerRepository>();
            var crawler = new RabotaUaCrawler(_logger);

            var document = new HtmlDocument();
            document.Load(new FileStream("TestData/rabotaua/rabotaua.results.htm", FileMode.Open));
            loader.Setup(l => l.LoadDocument("http://rabota.ua/jobsearch/vacancy_list?rubricIds=8,9&keyWords=&parentId=1&pg=1")).Returns(document);
            loader.Setup(l => l.LoadDocument("http://rabota.ua/jobsearch/vacancy_list?rubricIds=8,9&keyWords=&parentId=1&pg=2")).Returns(new HtmlDocument());
            var vacancy = new HtmlDocument();
            vacancy.Load(new FileStream("TestData/rabotaua/dnet.withtdd.htm", FileMode.Open));
            loader.Setup(l => l.LoadDocument(It.IsRegex(@"http://rabota.ua/company\d+/vacancy\d+"))).
                Returns(vacancy);

            var storage = new List<TddDemandRecord>();
            context.Setup(c => c.Add(It.IsAny<TddDemandRecord>())).Callback((TddDemandRecord r) => storage.Add(r));

            //act
            crawler.Crawle(loader.Object, context.Object);

            //assert
            context.Verify(c => c.SaveChanges());
            Assert.That(storage.Count, Is.EqualTo(20), "Expected that all 20 divs processed");
        }
        public void Smoke()
        {
            //arrange
            var crawler = new RabotaUaCrawler(_logger);

            //act/assert
            Assert.That(crawler, Is.Not.Null);
        }
Exemplo n.º 3
0
        private TddDemandRecord ProcessPagesAndReturnFirstRecord(string results, string vacancy)
        {
            //arrange
            var loader = new Mock<IHtmlDocumentLoader>();
            var context = new Mock<ICrawlerRepository>();
            var crawler = new RabotaUaCrawler(_logger);

            var resultsPage = new HtmlDocument();
            resultsPage.Load(new FileStream(results, FileMode.Open));
            loader.Setup(l => l.LoadDocument("http://rabota.ua/jobsearch/vacancy_list?rubricIds=8,9&keyWords=&parentId=1&pg=1")).
                Returns(resultsPage);
            //empty page to stop crawler
            loader.Setup(l => l.LoadDocument("http://rabota.ua/jobsearch/vacancy_list?rubricIds=8,9&keyWords=&parentId=1&pg=2")).
                Returns(new HtmlDocument());
            var vacancyPage = new HtmlDocument();
            vacancyPage.Load(new FileStream(vacancy, FileMode.Open));
            loader.Setup(l => l.LoadDocument("http://rabota.ua/company1074/vacancy4516336")).
                Returns(vacancyPage);

            var storage = new List<TddDemandRecord>();
            context.Setup(c => c.Add(It.IsAny<TddDemandRecord>())).Callback((TddDemandRecord r) => storage.Add(r));

            //act
            crawler.Crawle(loader.Object, context.Object);

            //return
            return storage.First();
        }