public void TestPromoteUserWithRoleModeratorFails() { var service = new UserService(_users, _roles, _mapper); var promotionRequest = new PromoteUserCommand { Id = 2 }; Assert.ThrowsAsync <EntityNotFoundException>(async() => await service.PromoteUser(promotionRequest)); }
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 })); }
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)); }
public async Task PromoteAsync(PromoteUserCommand command) { await Mediator.Send(command); }