Пример #1
0
        public IActionResult GetAllUsers()
        {
            var query  = new GetAllUsersQuery();
            var result = QueryDispatcher.Retrive <GetAllUsersQueryResult, GetAllUsersQuery>(query);

            return(Ok(result));
        }
        public async Task <IActionResult> GetAll([FromHeader] int page = 0, [FromHeader] int totalPerPage = 2)
        {
            var query  = new GetAllUsersQuery(page, totalPerPage);
            var result = await Mediator.Send(query);

            return(await ResponseBase(result));
        }
Пример #3
0
 public async Task <List <GetAllUsersViewModel> > Handle(GetAllUsersQuery request,
                                                         CancellationToken cancellationToken) =>
 await _dbContext.Users
 .Select(e => new GetAllUsersViewModel {
     Username = e.Username, Id = e.Id
 })
 .ToListAsync(cancellationToken);
Пример #4
0
        public async Task <ActionResult <IEnumerable <UserResponse> > > GetAll()
        {
            var query    = new GetAllUsersQuery();
            var response = await _mediator.Send(query);

            return(Ok(response));
        }
        public async Task ExistThreeUsers_Executed_ThreeUsersViewModel()
        {
            // Arrange
            var users = new List <User>
            {
                new User("Marlon", "marlon.ricci", DateTime.Now),
                new User("Micael", "micael.ricci", DateTime.Now),
                new User("Natalia", "natalia.spigolon", DateTime.Now)
            };

            var userRepository = new Mock <IUserRepository>();

            userRepository.Setup(sr => sr.GetAll()).Returns(Task.FromResult(users));

            var getAllUsersQuery        = new GetAllUsersQuery();
            var getAllUsersQueryHandler = new GetAllUsersQueryHandler(userRepository.Object);

            // Act
            var usersViewModel = await getAllUsersQueryHandler.Handle(getAllUsersQuery, new CancellationToken());

            // Assert
            Assert.NotNull(usersViewModel);
            Assert.Equal(users.Count, usersViewModel.Count);

            foreach (var user in users)
            {
                var userViewModel = usersViewModel.SingleOrDefault(s => s.Name == user.Name);

                Assert.NotNull(userViewModel);
            }

            userRepository.Verify(ur => ur.GetAll(), Times.Once);
        }
        public async Task <IEnumerable <UserResponse> > Handle(GetAllUsersQuery request,
                                                               CancellationToken cancellationToken)
        {
            var users = await _userService.GetAllAsync();

            return(_mapper.Map <IEnumerable <UserResponse> >(users));
        }
 public async Task <IEnumerable <UsersDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
 {
     return(await _context.Users
            .ProjectTo <UsersDto>(_mapper.ConfigurationProvider)
            .AsNoTracking()
            .ToListAsync(cancellationToken));
 }
Пример #8
0
            public async Task <List <GetAllUsersDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
            {
                var result = await context.Users.ToListAsync();

                if (result == null)
                {
                    throw new NotFoundException();
                }

                var users = mapper.Map <List <GetAllUsersDto> >(result);

                foreach (var user in users)
                {
                    var userInRole = await context.UserInRoles.SingleOrDefaultAsync(o => o.UserId == user.UserId);

                    if (userInRole == null)
                    {
                        continue;
                    }

                    var role = await context.Roles.FindAsync(userInRole.RoleId);

                    if (role == null)
                    {
                        continue;
                    }

                    user.RoleId   = role.RoleId;
                    user.RoleName = role.RoleName;
                }

                return(users.OrderByDescending(o => o.UserId).ToList());
            }
Пример #9
0
        public async Task <IEnumerable <ApplicationUser> > Handle(GetAllUsersQuery request,
                                                                  CancellationToken cancellationToken)
        {
            var users = await _userRepository.GetAll();

            return(users);
        }
Пример #10
0
 public async Task <IList <UserDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
 {
     return(await _context.Users
            .Where(e => !e.IsDeleted)
            .ProjectTo <UserDto>(_mapper.ConfigurationProvider)
            .ToListAsync(cancellationToken: cancellationToken));
 }
Пример #11
0
        public async Task <IActionResult> GetUser()
        {
            var query  = new GetAllUsersQuery();
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
        public async Task <IEnumerable <User> > GetAll()
        {
            var query  = new GetAllUsersQuery();
            var result = await _mediator.Send(query);

            return(result);
        }
Пример #13
0
 public PaginatedData <UserOutput> GetAllUsers(
     [FromServices] GetAllUsersQuery query,
     [FromQuery] Pagination pagination
     )
 {
     return(query.Execute(pagination));
 }
Пример #14
0
        public async Task GetAllUsersQueryShouldReturnList()
        {
            // Prepare
            var list = new List <User> {
                new User("123", "John Smith", new Address(0, 0, "The Address", true, ""))
            };

            _mockRepo.Setup(c => c.GetAllUsersAsync()).ReturnsAsync(list.AsEnumerable());

            var resultToMap = new List <User> {
                new User("123", "John Smith", new Address(0, 0, "The Address", true, ""))
            };
            var expected = _mapper.Map <IEnumerable <UserSummary> >(resultToMap);

            var handler = new GetAllUsersQueryHandler(_mockRepo.Object, _mapper);

            var query = new GetAllUsersQuery();
            // Act
            var actual = await handler.Handle(query, default);

            // Assert
            Assert.Collection(actual,
                              item =>
            {
                Assert.Equal("123", item.Id);
                Assert.Equal("John Smith", item.Name);
                Assert.Equal("The Address", item.Address.Name);
            }
                              );
        }
Пример #15
0
 public async Task <IEnumerable <UserDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
 {
     // TODO: Add paging
     return(await _usersDbContext.Users
            .ProjectTo <UserDto>(_mapper.ConfigurationProvider)
            .ToListAsync());
 }
        public async Task FourUsersExist_Executed_ReturnUserViewModels()
        {
            //Arrange
            var users = new List <User>
            {
                new User("Nome 1", "*****@*****.**", Convert.ToDateTime("15/04/1998"), "123456", "client"),
                new User("Nome 2", "*****@*****.**", Convert.ToDateTime("06/01/2000"), "@151293vsm", "freelancer"),
                new User("Nome 3", "*****@*****.**", Convert.ToDateTime("06/06/1989"), "@6789", "freelancer"),
                new User("Nome 4", "*****@*****.**", Convert.ToDateTime("10/12/1993"), "@151293smv", "client")
            };

            var userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(s => s.GetAllAsync().Result).Returns(users);

            var getAllUsersQuery        = new GetAllUsersQuery("");
            var getAllUsersQueryHandler = new GetAllUsersQueryHandler(userRepositoryMock.Object);

            //Act
            var userViewModelList = await getAllUsersQueryHandler.Handle(getAllUsersQuery, new CancellationToken());

            //Assert
            Assert.NotNull(userViewModelList);
            Assert.NotEmpty(userViewModelList);
            Assert.Equal(users.Count, userViewModelList.Count);

            userRepositoryMock.Verify(u => u.GetAllAsync().Result, Times.Once);
        }
Пример #17
0
        public async Task <ActionResult <IEnumerable <UserSummary> > > Get()
        {
            var query  = new GetAllUsersQuery();
            var result = await Mediator.Send(query);

            return(Ok(result));
        }
        public async Task ShouldReturn_ThreeMoviesExists_ReturnPagedListUserViewModel()
        {
            var fixture = new Fixture();
            var movies  = fixture.Create <List <User> >();

            var userParameters = new UserParameters();
            var pagedListMovie = new PagedList <User>(movies, movies.Count, 0, 0);

            var movieRepository = new Mock <IUserRepository>();

            var getAllMoviesQuery = new GetAllUsersQuery(userParameters);

            var getAllMovieQueryHandler = new GetAllUsersQueryHandler(movieRepository.Object);

            movieRepository.Setup(pr => pr.GetAllAsync(userParameters))
            .Returns(pagedListMovie);

            var usersPagedList = await getAllMovieQueryHandler.Handle(getAllMoviesQuery, new System.Threading.CancellationToken());;

            Assert.NotNull(usersPagedList);
            Assert.NotEmpty(usersPagedList);
            Assert.Equal(3, usersPagedList.TotalRecords);
            Assert.Equal(1, usersPagedList.TotalPages);
            Assert.Equal(50, usersPagedList.PageSize);
            Assert.IsType <PagedList <UserViewModel> >(usersPagedList);
            movieRepository.Verify(mr => mr.GetAllAsync(userParameters), Times.Once);
        }
Пример #19
0
        public async Task <IActionResult> Users()
        {
            var query  = new GetAllUsersQuery();
            var result = await _mediator.Send(query);

            return(result != null ? (IActionResult)Ok(result) : NotFound());
        }
Пример #20
0
        public async Task <IActionResult> GetAll()
        {
            var query  = new GetAllUsersQuery();
            var result = await Mediator.Send(query);

            return(await ResponseBase(result));
        }
Пример #21
0
        public IActionResult Search()
        {
            try
            {
                var currentUser = _context.Users.Find(userManager.GetUserId(User));
                if (currentUser is null)
                {
                    throw new DomainException(ErrorMessages.NotSignedIn);
                }

                var existingAccount = _userStore.GetByIdentityUserId(currentUser.Id);

                var GetAllUsers = new GetAllUsersQuery(_userStore, _FriendListStore,
                                                       _RequestStore, currentUser, existingAccount, signInManager);

                return(View(GetAllUsers.Handle()));
            }
            catch (DomainException ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction(ActionName.Login));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(RedirectToAction(ActionName.ServerError));
            }
        }
        public async Task <IEnumerable <UserDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
        {
            var users = await _dbContext.Users
                        .Select(sourse => _mapper.Map <UserDto>(sourse))
                        .ToListAsync(cancellationToken);

            return(users);
        }
Пример #23
0
        public async Task <List <GetAllUsersDto> > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
        {
            List <Domain.Entities.User> users = await _context.Users.ToListAsync();

            List <GetAllUsersDto> result = users.Select(u => u.ToGetAllUsersDto()).ToList();

            return(result);
        }
            public async Task <ServiceResponse <List <UserViewDto> > > Handle(GetAllUsersQuery request, CancellationToken cancellationToken)
            {
                var Users = await userRepository.GetAll();

                var viewModel = mapper.Map <List <UserViewDto> >(Users);

                return(new ServiceResponse <List <UserViewDto> >(viewModel));
            }
Пример #25
0
        public async Task <IActionResult> Get()
        {
            //var users = _userService.GetAll();
            var query = new GetAllUsersQuery();
            var users = await _mediator.Send(query);

            return(Ok(users));
        }
Пример #26
0
        public async Task <ActionResult> Get()
        {
            var query  = new GetAllUsersQuery();
            var result = await _mediator.Send(query);

            _logger.LogInformation($"Get all users at {DateTime.Now}");
            return(Ok(result));
        }
Пример #27
0
        public async Task <ActionResult> Get()
        {
            var query = new GetAllUsersQuery {
            };
            var users = await _queryHandler.HandleAsync(query);

            return(Ok(users));
        }
Пример #28
0
        public async Task <IEnumerable <UserInfo> > HandleAsync(GetAllUsersQuery _)
        {
            var users = await _repository.GetAll();

            return(users.Select(user => {
                return _mapper.Map <UserInfo>(user);
            }));
        }
Пример #29
0
        public async Task NotNull()
        {
            var query   = new GetAllUsersQuery();
            var handler = new GetAllUsersHandler(_mock.Object);

            var result = await handler.Handle(query, CancellationToken.None);

            Assert.NotNull(result);
        }
Пример #30
0
        public async Task HasResult()
        {
            var query   = new GetAllUsersQuery();
            var handler = new GetAllUsersHandler(_mock.Object);

            var result = await handler.Handle(query, CancellationToken.None);

            Assert.AreEqual(result.Count, 3);
        }
Пример #31
0
        public void Sholud_Update_A_Create_User()
        {
            var newUser = CreateNewUser();

            new CreateUserCommand(_connectionString, newUser).Execute();
            newUser.Email = "*****@*****.**";

            var userUpdated = new GetAllUsersQuery(_connectionString).Execute().ToList();
            var usrUpdate = userUpdated[0];

            usrUpdate.Email = "*****@*****.**";

            new UpdateUserCommand(_connectionString, usrUpdate).Execute();

            var userListExpected = new GetAllUsersQuery(_connectionString).Execute().ToList();
            var userExpected = userListExpected[0];

            Assert.AreEqual(newUser.FirstName, userExpected.FirstName);
            Assert.AreEqual(newUser.LastName, userExpected.LastName);
            Assert.AreEqual(newUser.Email, userExpected.Email);
        }
Пример #32
0
        public void Should_Create_A_User_In_The_Table()
        {
            var newUser = CreateNewUser();

            var db = new CreateUserCommand(_connectionString, newUser);
            db.Execute();

            var users = new GetAllUsersQuery(_connectionString).Execute();

            Assert.IsTrue(users.ToList().Count > 0);
        }
Пример #33
0
        public void Should_Return_All_Users_In_The_Table()
        {
            var newUser = CreateNewUser();
            var dbCreate = new CreateUserCommand(_connectionString, newUser);
            dbCreate.Execute();

            var dbGet = new  GetAllUsersQuery(_connectionString);
            IEnumerable<User>  users = dbGet.Execute();
            Assert.IsTrue(users.ToList().Count > 0);
        }