Exemplo n.º 1
0
        public void Parse_Success_ReturnsUnionOfAllResults()
        {
            var fixture = new Fixture();
            var results = new List <Result <AgentCollection> >();
            var agentCollectionCount = fixture.Create <int>();
            var agentCollections     = fixture.CreateMany <AgentCollection>(agentCollectionCount);

            foreach (var ac in agentCollections)
            {
                results.Add(Result.Ok(ac));
            }
            var initialCount   = fixture.Create <int>();
            var initialResults = fixture.CreateMany <Agent>(initialCount).ToList();

            var result = _agentCollectionResultParser.Parse(results, initialResults);

            result.Value.Sum(z => z.Value.ListingCount).Should().Be(initialCount + agentCollections.Sum(z => z.FetchedAgents.Count));
        }
        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));
        }