Пример #1
0
        public async Task <CommunityResponseModel> GetCommunities(CommunityCriteriaModel criteriaModel)
        {
            var criteria         = _modelFactory.CreateCommunityCriteria(criteriaModel);
            var communitiesCount = await _communityDao.CountCommunities(criteria).ConfigureAwait(false);

            var communityResponse = new CommunityResponse
            {
                Links = new List <Link>()
                        .AddFirstPage(communitiesCount)
                        .AddLastPage(communitiesCount, criteria.PageSize)
                        .AddNextPage(communitiesCount, criteria.PageSize, criteria.Page)
                        .AddPreviousPage(communitiesCount, criteria.Page)
            };

            if (communitiesCount > 0 && criteria.Page.IsPageInRange(communitiesCount, criteria.PageSize))
            {
                communityResponse.Results = (await _communityDao.GetCommunities(criteria).ConfigureAwait(false))
                                            .Paginate(criteria.Page, criteria.PageSize);
            }
            else
            {
                communityResponse.Results = new List <Community>();
            }


            return(_modelFactory.CreateCommunityResponseModel(communityResponse));
        }
Пример #2
0
        public void Should_Get_Artifacts_When_results_exist()
        {
            _communityDao.CountCommunities(Arg.Any <CommunityCriteria>()).ReturnsForAnyArgs(50);
            _communityDao.GetCommunities(Arg.Any <CommunityCriteria>())
            .ReturnsForAnyArgs(_fixture.CreateMany <Community>(50));

            var criteria = new CommunityCriteriaModel
            {
                Page     = 1,
                PageSize = 20
            };

            var results = _communityRepo.GetCommunities(criteria).Result;

            results.Results.Should().NotBeEmpty();
            results.Results.Count().Should().Be(20);
        }