public void Given_A_Null_Role_When_I_Call_UpdateRole_Then_An_ArgumentNullException_Is_Thrown() { //arrange var updateUserRoleDto = new UpdateUserRoleDto { Role = null }; //act && assert var exception = Assert.Throws <ArgumentNullException>(() => _sut.UpdateRole(_userName, updateUserRoleDto)); Assert.AreEqual("updateUserRoleDto.Role", exception.ParamName); }
public void Given_An_Empty_Role_When_I_Call_UpdateRole_Then_An_ArgumentException_Is_Thrown() { //arrange var updateUserRoleDto = new UpdateUserRoleDto { Role = string.Empty }; //act && assert var exception = Assert.Throws <ArgumentException>(() => _sut.UpdateRole(_userName, updateUserRoleDto)); Assert.AreEqual("A value for the argument 'updateUserRoleDto.Role' must be supplied", exception.Message); }
public void Given_Valid_Arguments_When_I_Call_UpdateUser_Then_The_Correct_Service_Method_Is_Called() { //arrange var updateRoleDto = new UpdateUserRoleDto { Role = _role }; //act _sut.UpdateRole(_userName, updateRoleDto); //assert _blaiseApiMock.Verify(v => v.UpdateRole(_userName, updateRoleDto.Role), Times.Once); }
public IActionResult UpdateUserRole(int id, [FromBody] UpdateUserRoleDto model) { var user = _mapper.Map <User>(model); user.Id = id; try { // update user _userService.UpdateUserRole(user); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> UpdateRole(UpdateUserRoleDto model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user != null) { if (model.Delete) { await _userManager.RemoveFromRoleAsync(user, model.Role); } else { await _userManager.AddToRoleAsync(user, model.Role); } } return(Ok("FOI")); }
public async Task <IActionResult> UpdateUserRole([FromRoute] string id, [FromRoute] string userId, [FromBody] UpdateUserRoleDto dto) { var currentUserId = User.GetUserId(); var projectUser = await _repo.GetProjectUser(id, currentUserId); if (projectUser == null || projectUser.UserRole != Roles.MANAGER) { return(Unauthorized(new { Message = "You are not authorized to change user roles." })); } var projectUserToChange = await _repo.GetProjectUser(id, userId); if (projectUserToChange == null) { return(NotFound(new { Message = "User not found." })); } // [Security] check dto.Role value against 'user' and 'manager' // [Security] check total number of managers before updating projectUserToChange.UserRole = dto.Role; if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest(new { Message = "Error updating the user role." })); }