public async Task User_EditUser_Success() { var client = _factory.CreateClient(); var user = new StartupUserDto() { Name = "NewName", Password = "******" }; using var postContent = new ByteArrayContent(JsonSerializer.SerializeToUtf8Bytes(user, _jsonOptions)); postContent.Headers.ContentType = MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json); var postResponse = await client.PostAsync("/Startup/User", postContent).ConfigureAwait(false); Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode); var getResponse = await client.GetAsync("/Startup/User").ConfigureAwait(false); Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode); Assert.Equal(MediaTypeNames.Application.Json, getResponse.Content.Headers.ContentType?.MediaType); var contentStream = await getResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); var newUser = await JsonSerializer.DeserializeAsync <StartupUserDto>(contentStream, _jsonOptions).ConfigureAwait(false); Assert.Equal(user.Name, newUser !.Name); Assert.NotEmpty(newUser.Password); Assert.NotEqual(user.Password, newUser.Password); }
public async Task UpdateUser([FromForm] StartupUserDto startupUserDto) { var user = _userManager.Users.First(); user.Username = startupUserDto.Name; await _userManager.UpdateUserAsync(user).ConfigureAwait(false); if (!string.IsNullOrEmpty(startupUserDto.Password)) { await _userManager.ChangePassword(user, startupUserDto.Password).ConfigureAwait(false); } }
public async Task <ActionResult> UpdateStartupUser([FromBody] StartupUserDto startupUserDto) { var user = _userManager.Users.First(); user.Username = startupUserDto.Name; await _userManager.UpdateUserAsync(user).ConfigureAwait(false); if (!string.IsNullOrEmpty(startupUserDto.Password)) { await _userManager.ChangePassword(user, startupUserDto.Password).ConfigureAwait(false); } return(NoContent()); }