Exemplo n.º 1
0
        public void CalculateSkip_Return_Twenty()
        {
            //Arrange
            var pageInfo = new PageInfo(10, 3);

            //Act
            var skip = pageInfo.CalculateSkip();

            //Assert
            Assert.IsTrue(skip == 20);
        }
Exemplo n.º 2
0
        public async Task <PagedResult <DomainUser> > GetAll(PageInfo pageInfo, CancellationToken cancellationToken)
        {
            var findOptions = new FindOptions <User, User> {
                Skip = pageInfo.CalculateSkip(), Limit = pageInfo.PageSize
            };

            var users       = (await _context.Users.FindAsync(FilterDefinition <User> .Empty, findOptions, cancellationToken)).ToList();
            var domainUsers = _mapper.Map <IEnumerable <DomainUser> >(users);

            pageInfo.TotalCount = await _context.Users.CountDocumentsAsync(FilterDefinition <User> .Empty, null, cancellationToken);

            return(new PagedResult <DomainUser>(domainUsers, pageInfo));
        }
Exemplo n.º 3
0
        public async Task Call_GetAll_ShouldCall_FindAsyncOnDbContext_And_ReturnPagedUsersList(int pageSize, int pageIndex, int expcetedPagedUserCount)
        {
            // Arrange
            var pageInfo = new PageInfo(pageSize, pageIndex);
            var users    = new List <User>
            {
                new User {
                    Id = 1, Name = "John"
                },
                new User {
                    Id = 2, Name = "John"
                },
                new User {
                    Id = 3, Name = "John"
                },
                new User {
                    Id = 4, Name = "John"
                },
                new User {
                    Id = 5, Name = "John"
                }
            };

            var findOptions = new FindOptions <User, User> {
                Skip = pageInfo.CalculateSkip(), Limit = pageInfo.PageSize
            };

            FakeDbContextFactory.CreateMockCollection(_dbContextMock.Setup(db => db.Users), users, findOptions);

            // Act
            var pagedUsers = await _userRepository.GetAll(pageInfo, CancellationToken.None);

            // Assert
            Assert.Equal(expcetedPagedUserCount, pagedUsers.Result.Count());
            Assert.Equal(pageSize, pagedUsers.PageInfo.PageSize);
            Assert.Equal(pageIndex, pagedUsers.PageInfo.PageIndex);
            Assert.Equal(users.Count(), pagedUsers.PageInfo.TotalCount);
            _dbContextMock.Verify(db => db.Users.FindAsync(FilterDefinition <User> .Empty, It.IsAny <FindOptions <User, User> >(), It.IsAny <CancellationToken>()), Times.Once);
        }