Exemplo n.º 1
0
        /// <summary>
        /// Search Google for required key words
        /// </summary>
        /// <param name="keyWords">List of key words</param>
        /// <param name="maxSearchResults">Total number of search results to get</param>
        /// <returns>Pieces of html representing search results</returns>
        public override async Task <IEnumerable <string> > Search(
            IEnumerable <string> keyWords,
            int maxSearchResults = 100)
        {
            //TODO: Validate key words

            var searchUrls          = GetSearchRequestUrls(keyWords, maxSearchResults);
            var websitesHtmlContent = await _downloadService.DownloadWebsitesParallelAsync(searchUrls);

            return(GetAllSearchResultItems(websitesHtmlContent));
        }
Exemplo n.º 2
0
        public async Task GoogleSearchScraper_Search_ReturnsValidSearchResults()
        {
            // ASSERT:
            // Scraper is able to process multiple search downloads.
            // One of the results contains expected substring.

            _downloadService
            .DownloadWebsitesParallelAsync(urls: Arg.Any <IEnumerable <string> >())
            .Returns(new List <string> {
                testHtml, testHtml, testHtml
            });

            var SUT               = new GoogleSearchScraper(downloadService: _downloadService);
            var keyWords          = new string[] { "KEYWORD1", "KEYWORD2" };
            var maxSearchResults  = 100;
            var expectedSubstring = "www.sympli.com.au";

            var searchResults = await SUT.Search(keyWords, maxSearchResults) as List <string>;

            Assert.NotNull(searchResults);
            Assert.True(searchResults.Any(r => r.Contains(expectedSubstring)));
        }