Esempio n. 1
0
        public void TestPromoteUserWithRoleModeratorFails()
        {
            var service          = new UserService(_users, _roles, _mapper);
            var promotionRequest = new PromoteUserCommand {
                Id = 2
            };

            Assert.ThrowsAsync <EntityNotFoundException>(async() => await service.PromoteUser(promotionRequest));
        }
Esempio n. 2
0
        public async void TestPromoteUserWithRoleUser()
        {
            var service          = new UserService(_users, _roles, _mapper);
            var promotionRequest = new PromoteUserCommand {
                Id = 1
            };
            var r = await service.PromoteUser(promotionRequest);

            Assert.Equal("moderator", r.Role);
        }
        public async Task <IActionResult> PromoteUser(string userId)
        {
            var command = new PromoteUserCommand()
            {
                UserId = userId
            };

            _ = await Mediator.Send(command);

            return(RedirectToAction("EditUser", new { id = userId }));
        }
Esempio n. 4
0
        public async Task <DomainUser> PromoteUser(PromoteUserCommand cmd)
        {
            var user = await _users.FindById(cmd.Id);

            if (user?.Role?.RoleName != Roles.User)
            {
                throw new EntityNotFoundException(nameof(user), $"(id == {cmd.Id} && role == user)");
            }

            var modRole = await _roles.FindByRole(Roles.Moderator);

            user.Role = modRole;
            var promoted = await _users.UpdateUser(user);

            return(_mapper.Map <DomainUser>(promoted));
        }
Esempio n. 5
0
 public async Task PromoteAsync(PromoteUserCommand command)
 {
     await Mediator.Send(command);
 }