Exemple #1
0
        public async Task Fetch_NthPage_Succeeds()
        {
            var fixture               = new Fixture();
            var type                  = fixture.Create <string>();
            var path                  = fixture.Create <string>();
            var pageSize              = fixture.Create <int>();
            var page                  = fixture.Create <int>();
            var total                 = fixture.Create <int>();
            var agentCollection       = fixture.Create <AgentCollection>();
            var agentCollectionResult = Result.Ok(agentCollection);
            var responseMessage       = Result.Ok(new HttpResponseMessage());
            var validationResult      = Result.Ok();
            var query                 = new ListingFetcherQuery(type, path, pageSize);
            var queryString           = query.ToString(page);

            _jsonApiGetRequest.Setup(z => z.Execute(HttpClientNames.Funda, _apiKey, queryString)).ReturnsAsync(responseMessage);
            _httpResponseMessageJsonParser.Setup(z => z.Parse <AgentCollection>(responseMessage)).ReturnsAsync(agentCollectionResult);
            _agentCollectionResultValidator.Setup(z => z.Validate(agentCollectionResult, total, page)).Returns(validationResult);

            var result = await _listingFetcher.Fetch(query, page, total);

            _jsonApiGetRequest.Verify(z => z.Execute(HttpClientNames.Funda, _apiKey, queryString), Times.Once);
            _httpResponseMessageJsonParser.Verify(z => z.Parse <AgentCollection>(responseMessage), Times.Once);
            _agentCollectionResultValidator.Verify(z => z.Validate(agentCollectionResult, total, page), Times.Once);
            result.Should().Be(agentCollectionResult);
        }
        public async Task <Result <AgentCollection> > Fetch(ListingFetcherQuery query, int page, int total)
        {
            var fetchingResult = await Fetch(query.ToString(page));

            var validationResult = _agentCollectionResultValidator.Validate(fetchingResult, total, page);

            if (validationResult.IsFailed)
            {
                return(validationResult);
            }
            return(fetchingResult);
        }
Exemple #3
0
        public void ToString_ReturnsCorrectQuery()
        {
            var fixture        = new Fixture();
            var page           = fixture.Create <int>();
            var type           = fixture.Create <string>();
            var path           = fixture.Create <string>();
            var pageSize       = fixture.Create <int>();
            var query          = new ListingFetcherQuery(type, path, pageSize);
            var expectedResult = $"?type={type}&zo={path}&pagesize={pageSize}&page={page}";

            var result = query.ToString(page);

            result.Should().BeEquivalentTo(expectedResult);
        }