예제 #1
0
        public IEnumerable <ISearchResult> Search(string search, int page)
        {
            try
            {
                //Build search url
                var searchUrl = searchUrlBuilder.BuildSearchUrl(search, page);

                //Get the plane Html result
                var searchHtmlResult = searchWebClient.Search(searchUrl);

                //Parse html and convert it to Model
                IEnumerable <ISearchResult> searchResults = searchParser.Parse(searchHtmlResult);

                SetIncrementalId(searchResults);

                return(searchResults);
            }
            catch (Exception ex)
            {
                return(new List <ISearchResult>
                {
                    new SearchResult
                    {
                        Id = 1,
                        Title = $"Error on page {page}",
                        Summary = ex.Message
                    }
                });
            }
        }
예제 #2
0
        public void BuildSearchUrl_Page1()
        {
            //Arrange
            var expected = "https://www.bing.com/search?q=Hello+World!&first=1";

            //Act
            var actual = bingSearchUrlBuilder.BuildSearchUrl("Hello World!", 1);

            //Assert
            Assert.AreEqual(actual, expected);
        }
예제 #3
0
        public IEnumerable <ISearchResult> Search(string search, int page)
        {
            //TODO: implement error handling logic

            //Build search url
            var searchUrl = searchUrlBuilder.BuildSearchUrl(search, page);

            //Get the plane Html result
            var searchHtmlResult = searchWebClient.Search(searchUrl);

            //Parse html and convert it to Model
            IEnumerable <ISearchResult> searchResults = searchParser.Parse(searchHtmlResult);

            SetIncrementalId(searchResults);
            return(searchResults);
        }