August 2017
Intermediate to advanced
330 pages
7h 26m
English
In the Delete tests , we use the same pattern as the preceding test. We create our resource as we did before. Then use HttpClient to call Delete, and assert that the response we get back is an okay:
[TestMethod]
public async Task ReturnOkForDelete()
{
// arrange
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(_baseUri);
//arrange
StoreModel storeModel = GreenStoreModel();
storeModel.Id = Guid.NewGuid();
HttpResponseMessage response = await client.PostAsJsonAsync("stores", storeModel);
// act
string deleteUri = string.Format("stores/{0}", storeModel.Id);
response = await client.DeleteAsync(deleteUri);
// assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
}
}