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

            var resultsPage = new HtmlDocument();
            resultsPage.Load(new FileStream("TestData/rabotaua/rabotaua.java.htm", 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 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());
            loader.Verify(l => l.LoadDocument("http://rabota.ua/company1074/vacancy4516336"));
            Assert.That(storage.Count, Is.EqualTo(1), "Expected that all 1 divs processed");
        }
Esempio n. 2
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();
        }