public async Task Test_Delete_Computer() { using (var client = new APIClientProvider().Client) { var computerGetOriginalComputer = await client.GetAsync("api/product"); string computerGetResponseBody = await computerGetOriginalComputer.Content.ReadAsStringAsync(); var computerList = JsonConvert.DeserializeObject <List <Computer> >(computerGetResponseBody); Assert.Equal(HttpStatusCode.OK, computerGetOriginalComputer.StatusCode); int deleteLastComputerObject = computerList.Count - 1; var computerObject = computerList[deleteLastComputerObject]; var response = await client.DeleteAsync($"api/product/{computerObject.Id}"); string responseBody = await response.Content.ReadAsStringAsync(); var getComputer = await client.GetAsync($"api/product/{computerObject.Id}"); getComputer.EnsureSuccessStatusCode(); string getComputerBody = await getComputer.Content.ReadAsStringAsync(); Computer newComputer = JsonConvert.DeserializeObject <Computer>(getComputerBody); Assert.Equal(HttpStatusCode.NoContent, getComputer.StatusCode); } }
// Reusable method to delete a Computer from the database public async Task deleteDummyComputer(Computer computerToDelete) { using (HttpClient client = new APIClientProvider().Client) { HttpResponseMessage deleteResponse = await client.DeleteAsync($"{url}/{computerToDelete.Id}"); } }
public async Task Test_Delete_Product() { using (var client = new APIClientProvider().Client) { var productGetInitialResponse = await client.GetAsync("api/product"); string initialResponseBody = await productGetInitialResponse.Content.ReadAsStringAsync(); var productList = JsonConvert.DeserializeObject <List <Product> >(initialResponseBody); Assert.Equal(HttpStatusCode.OK, productGetInitialResponse.StatusCode); int deleteLastProductObject = productList.Count - 1; var productObject = productList[deleteLastProductObject]; var response = await client.DeleteAsync($"api/product/{productObject.Id}"); string responseBody = await response.Content.ReadAsStringAsync(); //Assert.Equal(HttpStatusCode.OK, response.StatusCode); var getProduct = await client.GetAsync($"api/product/{productObject.Id}"); getProduct.EnsureSuccessStatusCode(); string getProductBody = await getProduct.Content.ReadAsStringAsync(); Product newProduct = JsonConvert.DeserializeObject <Product>(getProductBody); Assert.Equal(HttpStatusCode.NoContent, getProduct.StatusCode); } }
// Reusable method to deelte a PaymentType from the database public async Task deleteDummyPaymentType(PaymentType paymentTypeToDelete) { using (HttpClient client = new APIClientProvider().Client) { HttpResponseMessage deleteResponse = await client.DeleteAsync($"{url}/{paymentTypeToDelete.Id}"); } }
public async Task Delete_Coffee() { using (var client = new APIClientProvider().Client) { HttpResponseMessage response = await client.DeleteAsync($"/api/coffees/{fixture.TestCoffee.Id}"); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); } }
public async Task Test_Delete_NonExistent_ProductType_Fails() { using (var client = new APIClientProvider().Client) { // Try to delete an Id that shouldn't exist HttpResponseMessage deleteResponse = await client.DeleteAsync($"{url}0000000000"); Assert.False(deleteResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.NotFound, deleteResponse.StatusCode); } }
public async Task Test_Create_And_Delete_Animal() { using (var client = new APIClientProvider().Client) { /* * ARRANGE */ Animal Berry = new Animal { Name = "Berry Blue", Species = "Pygmy Three-toed Sloth", EatingHabit = "Omnivore", Legs = 4, ZooId = 1 }; var BerryAsJSON = JsonConvert.SerializeObject(Berry); /* * ACT */ var response = await client.PostAsync( "/api/animals", new StringContent(BerryAsJSON, Encoding.UTF8, "application/json") ); string responseBody = await response.Content.ReadAsStringAsync(); var NewBerry = JsonConvert.DeserializeObject <Animal>(responseBody); /* * ASSERT */ Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.Equal(Berry.Name, NewBerry.Name); Assert.Equal(Berry.Species, NewBerry.Species); Assert.Equal(Berry.EatingHabit, NewBerry.EatingHabit); Assert.Equal(Berry.Legs, NewBerry.Legs); Assert.Equal(Berry.ZooId, NewBerry.ZooId); /* * ACT */ var deleteResponse = await client.DeleteAsync($"/api/animals/{NewBerry.Id}"); /* * ASSERT */ Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode); } }
public async Task Test_Delete_One_Order() { using (var client = new APIClientProvider().Client) { var deleteResponse = await client.DeleteAsync("/api/order/15"); string responseBody = await deleteResponse.Content.ReadAsStringAsync(); var order = JsonConvert.DeserializeObject <Order>(responseBody); Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode); } }
public async Task Test_Delete_Student() { using (var client = new APIClientProvider().Client) { var response = await client.DeleteAsync("/api/student/3"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var getDeletedStudent = await client.GetAsync("/api/student/3"); getDeletedStudent.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.NoContent, getDeletedStudent.StatusCode); } }
public async Task Test_Delete_NonExistent_Animal_Fails() { using (var client = new APIClientProvider().Client) { /* * ARRANGE */ /* * ACT */ var deleteResponse = await client.DeleteAsync("/api/animals/600000"); /* * ASSERT */ Assert.False(deleteResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.NotFound, deleteResponse.StatusCode); } }