Ejemplo n.º 1
0
        public async Task AddOrder_ShouldReturnNewOrder()
        {
            Order order = new Order
            {
                FirstName = "TestOrder",
                OrderDate = new DateTime(2020, 11, 09),
                Status    = Library.Models.OrderStatus.Delivered
            };

            using (var client = new TestClientProvider().Client)
            {
                // Arrange
                var beforeResponse = await client.GetStringAsync("api/order/getallorders");

                int    countBefore = JsonConvert.DeserializeObject <List <Order> >(beforeResponse).Count;
                string json        = JsonConvert.SerializeObject(order);
                var    content     = new StringContent(json, Encoding.UTF8, "application/json");
                var    response    = await client.PostAsync("api/order/AddOrder", content);

                // Act
                var afterResponse = await client.GetStringAsync("api/order/getallorders");

                int actual = JsonConvert.DeserializeObject <List <Order> >(afterResponse).Count;

                var responseString = await response.Content.ReadAsStringAsync();

                var getOrder = JsonConvert.DeserializeObject <Order>(responseString);
                await client.DeleteAsync($"api/order/deletesingleorder?id={getOrder.Id}");

                Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                Assert.Equal(countBefore + 1, actual);
            }
        }