August 2017
Intermediate to advanced
330 pages
7h 26m
English
[TestMethod]
public async Task ReturnCreatedForAPost()
{
// arrange
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(_baseUri);
//act
StoreModel storeModel = GreenStoreModel();
HttpResponseMessage response = await client.PostAsJsonAsync( "stores", storeModel);
// assert
response.Should().NotBeNull();
response.StatusCode.Should().Be(HttpStatusCode.Created);
// clean up
await DeleteStore(client, storeModel.Id);
}
}
We use the standard HttpClient wrapping this in a using statement, so the client can be cleaned up when we exit the test. The common pattern here is used with the other actions as well.
Read now
Unlock full access