Esempio n. 1
0
        public async void Crawl()
        {
            var runner  = new CrawlRunner(_baseUrl, new HttpClient(new FakeHandler()), _parser, _sanitiser);
            var results = await runner.Crawl();

            var testPage     = new Uri("https://testing.com/");
            var expectedPage = new Page
            {
                InLinks = new List <Uri> {
                    new Uri("https://testing.com/second.html")
                },
                OutLinks = new List <Uri> {
                    new Uri("https://testing.com/first.html"), new Uri("https://testing.com/second.html"), new Uri("https://testing.com/error.html")
                },
                Status = CrawlStatus.Success,
                Title  = "Index page",
                Url    = testPage
            };

            Assert.Equal(expectedPage.Title, results[testPage].Title);
            Assert.Equal(expectedPage.Status, results[testPage].Status);
            Assert.Equal(expectedPage.Url, results[testPage].Url);
            Assert.Equal(expectedPage.OutLinks, results[testPage].OutLinks);
            Assert.Equal(expectedPage.InLinks, results[testPage].InLinks);
        }
Esempio n. 2
0
        public async void Parse_Links_Sanitises()
        {
            var fakesanitiser = A.Fake <UrlSanitiser>(x => x.CallsBaseMethods().WithArgumentsForConstructor(() => new UrlSanitiser(_baseUrl)));
            var runner        = new CrawlRunner(_baseUrl, new HttpClient(new FakeHandler()), _parser, fakesanitiser);
            var results       = await runner.Crawl();

            A.CallTo(() => fakesanitiser.SanitiseLocal(A <string> .Ignored)).MustHaveHappened();
        }
Esempio n. 3
0
        public async void Parse_Title()
        {
            var runner  = new CrawlRunner(_baseUrl, new HttpClient(new FakeHandler()), _parser, _sanitiser);
            var results = await runner.Crawl();

            Assert.Equal("Index page", results[new Uri("https://testing.com")].Title);
            Assert.Equal("First page", results[new Uri("https://testing.com/first.html")].Title);
            Assert.Equal("Second page", results[new Uri("https://testing.com/second.html")].Title);
        }
Esempio n. 4
0
        public async void Parse_Links_Duplicate()
        {
            var runner  = new CrawlRunner(_baseUrl, new HttpClient(new FakeHandler()), _parser, _sanitiser);
            var results = await runner.Crawl();

            var expectedLinks = new List <string> {
                "https://testing.com/", "https://testing.com/first.html"
            };
            var actualLinks = results[new Uri("https://testing.com/second.html")].OutLinks.Select(x => x.ToString()).ToList();

            Assert.Equal(expectedLinks, actualLinks);
        }