public async Task Should_Modify_Price_Of_Pets_When_Patch() { //given Pet pet = new Pet(name: "Baymax", type: "dog", color: "white", price: 5000); UpdatePriceModel upDating = new UpdatePriceModel(name: "Baymax", price: 200); Pet updatedPet = new Pet(name: "Baymax", type: "dog", color: "white", price: 200); string request = JsonConvert.SerializeObject(pet); string requestUpdate = JsonConvert.SerializeObject(upDating); StringContent requestBody = new StringContent(request, Encoding.UTF8, "application/json"); StringContent updateBody = new StringContent(requestUpdate, Encoding.UTF8, "application/json"); //when await client.PostAsync("petStore/addNewPet", requestBody); var patchResponse = await client.PatchAsync("petStore/Baymax", updateBody); await client.GetAsync("petStore?name=Baymax"); //then patchResponse.EnsureSuccessStatusCode(); var responseString = await patchResponse.Content.ReadAsStringAsync(); Pet actualPet = JsonConvert.DeserializeObject <Pet>(responseString); Assert.Equal(updatedPet, actualPet); }
public Pet UpdatePriceByName(UpdatePriceModel updateModel) { pets.Where(pet => pet.Name == updateModel.Name).ToList()[0].Price = updateModel.Price; return(pets.FirstOrDefault(pet => pet.Name == updateModel.Name)); }