public async Task <Result <ListingCountPerAgent> > GetMostActiveAgents(int count, string type, string filterPath) { var query = new ListingFetcherQuery(type, filterPath, ApiConstants.MaxPageSize); var fetchingResult = await _agentFetcher.Fetch(query); if (fetchingResult.IsFailed) { return(fetchingResult.ToResult()); } var initialData = fetchingResult.Value; var pageCount = (int)Math.Ceiling((double)initialData.TotalFound / ApiConstants.MaxPageSize); var results = await _taskBatcher.BatchExecute(pageCount, (page) => _agentFetcher.Fetch(query, page, initialData.TotalFound)); var parsedResults = _agentCollectionResultParser.Parse(results, initialData.FetchedAgents); return(parsedResults.GetMostActive(count)); }
public async Task Fetch_FirstPage_Succeeds() { var fixture = new Fixture(); var type = fixture.Create <string>(); var path = fixture.Create <string>(); var pageSize = fixture.Create <int>(); var agentCollection = fixture.Create <AgentCollection>(); var agentCollectionResult = Result.Ok(agentCollection); var responseMessage = Result.Ok(new HttpResponseMessage()); var query = new ListingFetcherQuery(type, path, pageSize); var queryString = query.FirstPageQueryToString(); _jsonApiGetRequest.Setup(z => z.Execute(HttpClientNames.Funda, _apiKey, queryString)).ReturnsAsync(responseMessage); _httpResponseMessageJsonParser.Setup(z => z.Parse <AgentCollection>(responseMessage)).ReturnsAsync(agentCollectionResult); var result = await _listingFetcher.Fetch(query); _jsonApiGetRequest.Verify(z => z.Execute(HttpClientNames.Funda, _apiKey, queryString), Times.Once); _httpResponseMessageJsonParser.Verify(z => z.Parse <AgentCollection>(responseMessage), Times.Once); result.Should().Be(agentCollectionResult); }