public async Task <IActionResult> PutAsync(PetUpdateModel data) { try { await petService.UpdatePetAsync(data); return(Ok()); } catch (Exception ex) { throw ex; } }
public async Task Should_modify_price_when_patch() { Pet pet = new Pet(name: "Baymax", type: "dog", color: "white", price: 5000); StringContent requestBody = new StringContent(JsonConvert.SerializeObject(pet), Encoding.UTF8, "application/json"); await client.PostAsync("pets", requestBody); PetUpdateModel petUpdate = new PetUpdateModel(name: "Baymax", price: 3000); StringContent updateRequestBody = new StringContent(JsonConvert.SerializeObject(petUpdate), Encoding.UTF8, "application/json"); var response = await client.PatchAsync("pets/Baymax", updateRequestBody); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); Pet actualPet = JsonConvert.DeserializeObject <Pet>(responseString); Assert.Equal(3000, actualPet.Price); }