public async Task <List <SearchResultDto> > Find(SearchRequestDto model) { var searchSystems = GetSearchSystems(_apiKeyOptions); SearchExecuter searchExecuter = new SearchExecuter(searchSystems); var searchResults = searchExecuter.ExecuteSearch(model.KeyWord); if (searchResults?.Count > 0) { await _searchResultRepository.AddRangeAsync(_mapper.Map <IEnumerable <SearchResult> >(searchResults)); await _unitOfWork.SaveChangesAsync(); } return(searchResults); }
public void Test_GoogleSearch() { var searchSystems = new List <ISearchSystem> { new GoogleSearchSystem(null, options.GoogleKey, options.GoogleCx) }; SearchExecuter searchExecuter = new SearchExecuter(searchSystems); var searchResults = searchExecuter.ExecuteSearch("game").Take(1).ToList(); var manualResult = new List <SearchResultDto>() { new SearchResultDto { BrowserType = SearchSystemType.Google, Name = "Connected games", Url = "https://www.google.com/appserve/mkt/p/AFnwnKUnXD1ji46geUqp7D9dO_-JdN-nkd-9-tW67x-ubTby1HUZpTyHG9o4tXFXHXLGbfH6wSWIt7VOmmtywryT8NAxxMXmx8Rn4q5-8ygMVFsqZsWrTZ7irqvsJ6ZnL31Ck4qfCHEFR92FfxnoEBgh4-U4jC7TwGNU2y1xfJd9UgrSxF1QUQeNw0jY", Snippet = "The next generation of multiplayer games and beyond with Unity and Google \nCloud.", DateTime = searchResults[0].DateTime } }; CollectionAssert.AreEqual(manualResult, searchResults, new SearchResultComparer()); }
public void Test_YandexSearch() { var searchSystems = new List <ISearchSystem> { new YandexSearchSystem(null, options.YandexKey, options.YandexUser) }; SearchExecuter searchExecuter = new SearchExecuter(searchSystems); var searchResults = searchExecuter.ExecuteSearch("Pi").Take(1).ToList(); var manualResult = new List <SearchResultDto>() { new SearchResultDto { BrowserType = SearchSystemType.Yandex, Name = "Пи (число) — Википедия", Url = "https://ru.wikipedia.org/wiki/%D0%9F%D0%B8_(%D1%87%D0%B8%D1%81%D0%BB%D0%BE)", Snippet = "π {\\displaystyle \\pi }. Десятичная.\nЧисло. π {\\displaystyle \\pi }.", DateTime = searchResults[0].DateTime } }; CollectionAssert.AreEqual(manualResult, searchResults, new SearchResultComparer()); }