public async Task<Response<SearchResponse>> Search(SearchRequest query)
 {
     Response<SearchResponse> result = new Response<SearchResponse>();
     try
     {
         result.Data = await _movieService.Search(query);
     }
     catch (Exception) 
     {
         result.IsError = true;
     }
     return result;
 }
 public async Task<SearchResponse> Search(SearchRequest q)
 {
     if (q.PageIndex < 0 || q.PageSize < 0 || string.IsNullOrEmpty(q.Query))
     {
         throw new ArgumentException("q", "Search Request is incorrect. PageIndex, PageSize cannot be less than 0, Query cannot be empty.");
     }
     List<IEnumerable<Movie>> result = new List<IEnumerable<Movie>>();
     int totalCount = 0;
     foreach (var dataService in _dataServices) 
     {
         var searchRes = await dataService.Search(q, (q.PageIndex + 1) * q.PageSize);
         result.Add(searchRes.Movies);
         totalCount += searchRes.TotalResults;
     }
         
     return new SearchResponse()
     {
         Movies = GetPage(q.PageIndex, q.PageSize, result),
         TotalResults = totalCount
     };
 }
 public async Task SearchPagesNotChangeWhenPaging()
 {
     Action<string[], SearchResponse, Action<string, Movie>> checkPage = new Action<string[], SearchResponse, Action<string, Movie>>(
         (pageIds, response, checkFunc) => 
         {
             var page = response.Movies.ToList();
             for (var i = 0; i < page.Count; i++) 
             {
                 checkFunc(pageIds[i], page[i]);
             }
         });
     var firstPageIds = new string[] { "OMDB-0", "OMDB-1", "OMDB-2", "OMDB-3", "OMDB-4", "Youtube-0", "Youtube-1", "Youtube-2", "Youtube-3", "Youtube-4" };
     var request = new SearchRequest() { PageIndex = 0, PageSize = 10, Query = "Test Query" };
     checkPage(firstPageIds, await _service.Search(request), (id, m) => Assert.AreEqual(id, m.SourceId));
     request.PageIndex = 3;
     checkPage(firstPageIds, await _service.Search(request), (id, m) => Assert.AreNotEqual(id, m.SourceId));
     request.PageIndex = 0;
     checkPage(firstPageIds, await _service.Search(request), (id, m) => Assert.AreEqual(id, m.SourceId));
 }
 public async Task SearchTotalsCountIsCorrect()
 {
     var request = new SearchRequest() { PageIndex = 0, PageSize = 10, Query = "Test Query" };
     var response = await _service.Search(request);
     Assert.AreEqual(110, response.TotalResults);
 }
 public DataSearchRequest(SearchRequest request)
     : this()
 {
     this.Query = request.Query;
     this.Year = request.Year;
 }