public async Task Update_and_get_by_id_user() { //Arrange AddViewUsers addUser = new AddViewUsers { Login = "******", Name = "Name", Password = "******", Surname = "Surname", AccountImage = "" }; UpdateViewUsers updateUser = new UpdateViewUsers { Name = "UpdateName", Password = "******", Surname = "UpdateSurname" }; //Act var addResponse = await TestClient.PostAsync("/api/Users/newUser", new StringContent(JsonConvert.SerializeObject(addUser), Encoding.UTF8, "application/json")); int userId = serviceProvider.CreateScope() .ServiceProvider .GetRequiredService <JLDatabaseContext>() .Users.Single(u => u.Login == addUser.Login).Id; var updateResponse = await TestClient.PutAsync("/api/Users/updatingUser/" + userId, new StringContent(JsonConvert.SerializeObject(updateUser), Encoding.UTF8, "application/json")); var gettingResponse = await TestClient.GetAsync("/api/Users/" + userId); var resultUser = JsonConvert.DeserializeObject <InfoViewUsers>(await gettingResponse.Content.ReadAsStringAsync()); //Assert using (var scope = serviceProvider.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <JLDatabaseContext>(); string resultUserPassword = context.Users.Single(u => u.Login == addUser.Login).Password; updateResponse.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); gettingResponse.StatusCode.Should().Be(System.Net.HttpStatusCode.OK); Assert.Equal(resultUser.Name, updateUser.Name); Assert.Equal(resultUserPassword, updateUser.Password); Assert.Equal(resultUser.Surname, updateUser.Surname); } }
public async Task <IActionResult> UpdateUser(int id, UpdateViewUsers user) { int userId = await userRepository.UpdateUser(mapper.Map <Users>(user), id); return(Ok(userId)); }