コード例 #1
0
        public IActionResult Get()
        {
            var pagination = Request.Headers["Pagination"];

            if (!string.IsNullOrEmpty(pagination))
            {
                string[] vals = pagination.ToString().Split(',');
                int.TryParse(vals[0], out page);
                int.TryParse(vals[1], out pageSize);
            }

            int currentPage     = page;
            int currentPageSize = pageSize;
            var totalCountries  = countryRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalCountries / pageSize);

            IEnumerable <Country> countries = countryRepository
                                              .GetAll()
                                              .OrderBy(s => s.Id)
                                              .Skip((currentPage - 1) * currentPageSize)
                                              .Take(currentPageSize)
                                              .ToList();

            Response.AddPagination(page, pageSize, totalCountries, totalPages);

            IEnumerable <CountryViewModel> countriesVM = Mapper.Map <IEnumerable <Country>, IEnumerable <CountryViewModel> >(countries);

            return(new OkObjectResult(countriesVM));
        }
コード例 #2
0
        public void CountTest()
        {
            //Arrange
            ICountryRepository countryRepository = _unitOfWork.Repository.CountryRepository;

            //Act
            int count = countryRepository.Count();

            //Assert
            count.ShouldBe(2);
        }
コード例 #3
0
 public int CountryCount()
 {
     return(_countryRepository.Count());
 }