public async Task GetWishesOfCurrentUser_NoExceptionsWasThrown_ReturnsPaginatedBookGetDto()
        {
            var pageableParams = new PageableParams();

            await _service.GetWishesOfCurrentUserAsync(pageableParams);

            _userResolverServiceMock.Verify(obj => obj.GetUserId());
            _wishRepositoryMock.Verify(obj => obj.GetAll());
            _paginationServiceMock.Verify(obj => obj.GetPageAsync <BookGetDto, Book>(It.IsAny <IQueryable <Book> >(), pageableParams));
        }
        public async Task <PaginationDto <BookGetDto> > GetWishesOfCurrentUserAsync(PageableParams pageableParams)
        {
            var currentUserId = _userResolverService.GetUserId();

            var wishesQuery = _wishRepository.GetAll()
                              .Include(wish => wish.Book.Language)
                              .Include(wish => wish.Book.BookAuthor).ThenInclude(bookAuthor => bookAuthor.Author)
                              .Include(wish => wish.Book.BookGenre).ThenInclude(bookGenre => bookGenre.Genre)
                              .Include(wish => wish.Book.User.UserRoom.Location)
                              .Where(wish => wish.UserId == currentUserId)
                              .Select(wish => wish.Book);
            var wishesPaginated =
                await _paginationService.GetPageAsync <BookGetDto, Book>(wishesQuery, pageableParams);

            return(wishesPaginated);
        }
Exemplo n.º 3
0
        public async Task GetCurrentUserWishList_NoExceptionsWasThrown_ReturnsObjectResultWithPaginatedBookGetDto()
        {
            var pageableParams = new PageableParams();
            var paginatedBooks = new PaginationDto <BookGetDto>
            {
                Page       = new List <BookGetDto>(),
                TotalCount = 0
            };

            _wishListServiceMock.Setup(obj => obj.GetWishesOfCurrentUserAsync(pageableParams))
            .ReturnsAsync(paginatedBooks);

            var result = await _controller.GetCurrentUserWishList(pageableParams);

            _wishListServiceMock.Verify(obj => obj.GetWishesOfCurrentUserAsync(pageableParams), Times.Once);
            result.Value.Should().Be(paginatedBooks);
        }
Exemplo n.º 4
0
        public async Task <PaginationDto <TDto> > GetPageAsync <TDto, TEntity>(IQueryable <TEntity> query, PageableParams parameters)
            where TDto : class where TEntity : class
        {
            var wrapper = new PaginationDto <TDto>();

            if (parameters.FirstRequest)
            {
                wrapper.TotalCount = await query.CountAsync();
            }
            var pageResult = await query.Skip((parameters.Page - 1) *parameters.PageSize).Take(parameters.PageSize).AsNoTracking().ToListAsync();

            wrapper.Page = _mapper.Map <List <TDto> >(pageResult);
            return(wrapper);
        }
 public async Task <ActionResult <PaginationDto <BookGetDto> > > GetCurrentUserWishList([FromQuery] PageableParams pageableParams)
 {
     return(await _wishListService.GetWishesOfCurrentUserAsync(pageableParams));
 }