public async Task <IActionResult> Index(string query = null) { var viewModel = new SearchViewModel { Query = query }; if (!string.IsNullOrWhiteSpace(query)) { try { ITorrentFinderResponse result = await torrentFinderHttpService.SearchTitle(query); if (!result.Successful) { viewModel.ErrorMessage = $"We couldn't find any titles matching the search term \"{query}\"."; } else { viewModel.SearchResult = new SearchResultViewModel((TitleResponse)result); } } catch (Exception ex) { viewModel.ErrorMessage = "Sorry, but something went wrong on our end! Please try again."; Console.WriteLine(ex); } } return(View("~/Views/Search.cshtml", viewModel)); }
public async Task SearchTitle_WhenSuccessful_ReturnsTitleResponse() { // Arrange IRestResponse restResponse = GetDummySuccessfulRestResponse(); restClientMock .Setup(x => x.ExecuteTaskAsync(It.IsAny <IRestRequest>())) .Returns(Task.FromResult(restResponse)); // Act var resp = (TitleResponse)await service.SearchTitle(Helpers.GetRandomString()); // Assert Assert.IsTrue(resp.Successful); Assert.IsNotEmpty(resp.Media.Title); Assert.IsNotEmpty(resp.Media.PosterUrl); Assert.IsNotEmpty(resp.Media.Plot); Assert.IsNotEmpty(resp.Media.IMDBId); }