Example #1
0
        public async void Dispose()
        {
            using (var client = new TestClientProvider().Client)
            {
                var deleteResponse = await client.DeleteAsync($"/api/orders/{order.Id}");

                deleteResponse.EnsureSuccessStatusCode();
            }
        }
        public async Task Delete_Order_EmptyGuid_returns_NotFound()
        {
            var emptyGuid = Guid.Empty;

            using (var client = new TestClientProvider().Client)
            {
                var deleteresponse = await client.DeleteAsync($"/api/orders/{emptyGuid}");

                Assert.Equal(HttpStatusCode.NotFound, deleteresponse.StatusCode);
            }
        }
        public async Task Delete_Order_returns_Id()
        {
            var testOrder = new Order
            {
                Address    = "Testadress",
                City       = "Teststad",
                Email      = "*****@*****.**",
                FirstName  = "Testförnamn",
                LastName   = "Testefternamn",
                OrderDate  = DateTime.Now,
                Phone      = "123",
                ZipCode    = "123",
                Status     = Status.Packas,
                UserId     = Guid.NewGuid().ToString(),
                OrderItems = new List <OrderItem> {
                    new OrderItem {
                        Name = "Testprodukt2", Price = 48.00M, ProductId = Guid.NewGuid(), Quantity = 2
                    }
                }
            };

            using (var client = new TestClientProvider().Client)
            {
                var         payload = JsonConvert.SerializeObject(testOrder);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                //post testorder
                var postresponse = await client.PostAsync($"/api/orders/", content);

                var orderResponse = await postresponse.Content.ReadAsStringAsync();

                var order = JsonConvert.DeserializeObject <Order>(orderResponse);
                //delete testorder
                var deleteresponse = await client.DeleteAsync($"/api/orders/{order.Id}");

                var deletedOrderResponse = await deleteresponse.Content.ReadAsStringAsync();

                var deletedOrderId = JsonConvert.DeserializeObject <Guid>(deletedOrderResponse);

                Assert.Equal(order.Id, deletedOrderId);
            }
        }