public void SearchAsyncTest_empty_string() { var str = ""; var engine = new YandexEngine(); var res = engine.SearchAsync(str); Assert.IsInstanceOfType(res, typeof(System.Threading.Tasks.Task <Models.SearchResult>)); }
public void SearchAsyncTest_simple_string() { var str = "test"; var engine = new YandexEngine(); var res = engine.SearchAsync(str); Assert.IsInstanceOfType(res, typeof(System.Threading.Tasks.Task <Models.SearchResult>)); Assert.IsTrue(res.Result.results.Count > 0); }
public async Task <IActionResult> IndexAsync(string TextRequest) { //create instances of engines var google = new GoogleEngine(); var yandex = new YandexEngine(); var bing = new BingEngine(); //create a list of instances to execute them at the same time var allTasks = new List <Task <SearchResult> > { bing.SearchAsync(TextRequest), google.SearchAsync(TextRequest), yandex.SearchAsync(TextRequest) }; //when the first task was completed Task <SearchResult> finished = await Task.WhenAny(allTasks); allTasks.Clear(); SearchResult res = await finished; var limitedList = res.results.Take(10).ToList(); //save top 10 results foreach (var r in limitedList) { try { await _context.searchResultItems.AddAsync(r); await _context.SaveChangesAsync(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } SearchResultsViewModel resultsViewModel = new SearchResultsViewModel { resultItems = limitedList, fullText = (limitedList.Count == 0)? "Nothing found" : null }; return(View(resultsViewModel)); }