Beispiel #1
0
        public async Task <RetrieveBookingsResponse> RetrieveBookings(RetrieveBookingsRequest request)
        {
            RetrieveBookingsResponse     response;
            IEnumerable <BookingDetails> items;

            using (var db = _provider.GetDatabase())
            {
                var bookings = db.GetCollection <BookingDetails>("bookings");
                items = bookings.FindAll();
            }

            items = items.Sort(request.SortField, request.SortDescending);

            var itemsPerPage = request.ItemsPerPage ?? DEFAULT_ITEMS_PER_PAGE;
            var currentIndex = request.PageIndex ?? 0;
            var maxItems     = itemsPerPage + (itemsPerPage * currentIndex);

            var paged         = items.Skip(maxItems - itemsPerPage).Take(itemsPerPage);
            var lastPageIndex = items.Count() / itemsPerPage;
            var prevIndex     = currentIndex > 0 ? currentIndex - 1 : (int?)null;
            var nextIndex     = currentIndex < lastPageIndex ? currentIndex + 1 : (int?)null;

            response = new RetrieveBookingsResponse
            {
                Data             = paged,
                CurrentPageIndex = currentIndex,
                PrevPageIndex    = prevIndex,
                NextPageIndex    = nextIndex
            };

            return(await Task.FromResult(response));
        }
Beispiel #2
0
        public async void GetBookings_Should_Call_IBittnRepository_RetrieveBookings()
        {
            RetrieveBookingsRequest arg = null;

            _bittnRepository.RetrieveBookings(Arg.Do <RetrieveBookingsRequest>(a => arg = a)).Returns(new RetrieveBookingsResponse());

            var request = new GetBookingsRequest
            {
                PageIndex = 123
            };

            await _service.GetBookings(request);

            await _bittnRepository.Received(1).RetrieveBookings(Arg.Any <RetrieveBookingsRequest>());

            arg.ItemsPerPage.Should().BeNull();
            arg.PageIndex.Should().Be(request.PageIndex);
        }