Example #1
0
        public async Task <PageDto <UserDto> > GetUsers(SearchUserParamsDto searchParamsDTO)
        {
            if (searchParamsDTO == null)
            {
                throw new ArgumentNullException(nameof(searchParamsDTO));
            }
            var searchParams = _mapper.Map <SearchUsersParams>(searchParamsDTO);
            var usersPage    = await _userRepository.GetUsers(searchParams);

            return(_mapper.Map <PageDto <UserDto> >(usersPage));
        }
        public async Task <ActionResult <PageDto <UserDto> > > GetAllUsers([FromBody] SearchUserParamsDto searchParamsDTO)
        {
            try
            {
                var users = await _userService.GetUsers(searchParamsDTO);

                return(Ok(users));
            }
            catch (ArgumentNullException ex)
            {
                _logger.Error(ex.Message);
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #3
0
        public void GetUsers_WithSearchString_ReturnsListOfUsers(string searchString, int pageIndex, int pageSize)
        {
            // Arrange
            var users        = UserMocks.GetUsers();
            var searchParams = new SearchUsersParams()
            {
                SearchString = searchString,
                PageIndex    = pageIndex,
                PageSize     = pageSize
            };
            var result = new Page <User>()
            {
                Items       = users,
                PageCount   = 1,
                TotalCount  = 1,
                CurrentPage = 1
            };

            var searchParamsDto = new SearchUserParamsDto()
            {
                SearchString = searchString,
                PageIndex    = pageIndex,
                PageSize     = pageSize
            };

            _ = _mockUserRepository.Setup(x => x.GetUsers(It.IsAny <SearchUsersParams>())).ReturnsAsync(result);

            // Act
            var response = _userService.GetUsers(searchParamsDto).Result;
            var items    = response.Items.ToList();

            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(items[0].Name, "John");
            Assert.AreEqual(result.Items.Count(), users.Count());
        }