public async Task ReplaceUserAsync([NotNull] string userId, [NotNull] UserUpdateRequestDto dto) { var user = await FindUserAsync(userId); var mapped = mapper.Map(dto, user); user.UpdateDate = DateTime.UtcNow; await userRepository.ReplaceAsync(mapped); }
public async Task UpdateBrandAsync_Return_NoContent_Result(Mock <IUserService> userService) { // Arrange var sut = new AccountController(userService.Object); sut.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }; UserUpdateRequestDto dto = new UserUpdateRequestDto(); userService.Setup(setup => setup.ReplaceUserAsync(userId, dto)); // Act var result = sut.UpdateUserAsync(userId, dto); // Assert Assert.IsType <NoContentResult>(result.Result); Assert.IsNotType <OkObjectResult>(result.Result); Assert.IsNotType <CreatedAtActionResult>(result.Result); Assert.IsNotType <BadRequestObjectResult>(result.Result); Assert.IsNotType <AcceptedAtActionResult>(result.Result); }
public async Task <IdentityResult> UpdateUserAsync(UserUpdateRequestDto userSettingsUpdateRequestDto, string email) { if (userSettingsUpdateRequestDto == null) { return(null); } var applicationUser = await _userManager.FindByEmailAsync(email).ConfigureAwait(false); //ToDO: check if the password satisfies all the requirements. string passwordHash = string.IsNullOrWhiteSpace(userSettingsUpdateRequestDto.Password) ? applicationUser.PasswordHash : _userManager.PasswordHasher.HashPassword(applicationUser, userSettingsUpdateRequestDto.Password); applicationUser.UserName = userSettingsUpdateRequestDto.UserName ?? applicationUser.UserName; applicationUser.Bio = userSettingsUpdateRequestDto.Bio ?? applicationUser.Bio; applicationUser.Image = userSettingsUpdateRequestDto.ImageUrl ?? applicationUser.Image; applicationUser.Email = applicationUser.Email; applicationUser.PasswordHash = passwordHash; applicationUser.SecurityStamp = Guid.NewGuid().ToString(); return(await _userManager.UpdateAsync(applicationUser).ConfigureAwait(false)); }
public async Task <IActionResult> UpdateUserAsync(string userId, [FromBody] UserUpdateRequestDto model) { await userService.ReplaceUserAsync(userId, model); return(NoContent()); }