Пример #1
0
        public async Task <IActionResult> Index(int page = 1, string searchTerm = null)
        {
            GetUsers getUsersQuery = new GetUsers()
            {
                PageInfo   = new PageInfo(page, DefaultPageSize),
                SearchInfo = new SearchInfo(searchTerm)
            };

            IEnumerable <User> users = await this.getUsers.ExecuteAsync(getUsersQuery);

            GetUsersCount getUsersCountQuery = new GetUsersCount()
            {
                SearchInfo = new SearchInfo(searchTerm)
            };

            int usersCount = await this.getUsersCount.ExecuteAsync(getUsersCountQuery);

            IEnumerable <UserListingViewModel> usersModel =
                Mapper.Map <IEnumerable <UserListingViewModel> >(users);

            SearchViewModel <PaginatedViewModel <UserListingViewModel> > model =
                ViewModelFactory.CreateSearchPaginatedViewModel <UserListingViewModel>(
                    usersModel,
                    page,
                    DefaultPageSize,
                    usersCount,
                    searchTerm,
                    "users");

            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> PaginationAjax(string searchTerm)
        {
            GetUsersCount query = new GetUsersCount()
            {
                SearchInfo = new SearchInfo(searchTerm)
            };

            int songsCount = await this.getUsersCount.ExecuteAsync(query);

            return(ViewComponent(
                       typeof(PaginationComponent),
                       new
            {
                pageInfo = new PaginatedViewModel <string>(
                    null, 1, DefaultPageSize, songsCount),
                searchTerm = searchTerm,
                actionToCall = "index"
            }));
        }
Пример #3
0
        public async Task ReturnCountOfAllUsersInRepositoryWhenThePassedQueryContainsEmptySearchTerm()
        {
            var users = new[]
            {
                new User {
                    UserName = "******"
                },
                new User {
                    UserName = "******"
                },
                new User {
                    UserName = "******"
                }
            }
            .AsQueryable()
            .BuildMock();

            var userRepositoryStub = new Mock <IEfRepository <User> >();

            userRepositoryStub
            .Setup(x => x.All(It.IsAny <bool>()))
            .Returns(users.Object);

            int expectedUsersCount = 3;

            GetUsersCount query = new GetUsersCount()
            {
                SearchInfo = new SearchInfo(null)
            };

            // Arrange
            GetUsersCountQueryService sut =
                new GetUsersCountQueryService(userRepositoryStub.Object);

            // Act
            int actualUsersCount = await sut.ExecuteAsync(query);

            // Assert
            Assert.AreEqual(expectedUsersCount, actualUsersCount);
        }
Пример #4
0
        public async Task UsePassedUserRepositoryWhenInvoked()
        {
            // Arrange
            var users = new[]
            {
                new User {
                    UserName = "******"
                },
                new User {
                    UserName = "******"
                },
                new User {
                    UserName = "******"
                }
            }
            .AsQueryable()
            .BuildMock();

            var userRepositoryMock = new Mock <IEfRepository <User> >();

            userRepositoryMock.Setup(x => x.All(It.IsAny <bool>())).Returns(users.Object);

            GetUsersCountQueryService sut =
                new GetUsersCountQueryService(userRepositoryMock.Object);

            GetUsersCount query = new GetUsersCount()
            {
                SearchInfo = new SearchInfo(null)
            };

            // Act
            await sut.ExecuteAsync(query);

            // Assert
            userRepositoryMock.Verify(ur => ur.All(It.IsAny <bool>()), Times.Once());
        }