public async Task <IActionResult> PatchUser(int id, UserForPatchDto userForPatchDto) { var UserFromRepository = await _repository.GetUser(id); UserFromRepository.Status = userForPatchDto.status; if (await _repository.SaveAll()) { return(NoContent()); } throw new System.Exception($"Updating user {id} status failed on save"); }
public async Task Patch_ShouldReturn_NoContentForFoundUserAndValidUpdate() { // Arrange var jsonObject = new JsonPatchDocument <UserForPatchDto>(); var userToUpdate = new UserForPatchDto { FirstName = "Test", LastName = "Test", Username = "******", Password = "******", PizzaLove = 19 }; jsonObject.Replace(i => i.PizzaLove, userToUpdate.PizzaLove); // Act var response = await _userController.PatchAsync(1, jsonObject); // Assert Assert.IsType <NoContentResult>(response); }