Пример #1
0
        public async Task PostOrder_Returns_Ok()
        {
            var order = new Order
            {
                UserId        = Guid.NewGuid().ToString(),
                OrderProducts = new List <OrderProduct> {
                    new OrderProduct {
                        ProductId = 2, Quantity = 4
                    }
                },
                TotalPrice = 299.00M
            };

            using (var client = new TestClientProvider().Client)
            {
                var         payload = JsonSerializer.Serialize(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

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

                using (var responseStream = await response.Content.ReadAsStreamAsync())
                {
                    var updatedOrder = await JsonSerializer.DeserializeAsync <Order>(responseStream,
                                                                                     new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    var deleteresponse = await client.DeleteAsync($"/api/orders/{updatedOrder.Id}");

                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
                var deletedOrder = await client.DeleteAsync($"/api/orders/{order.Id}");
            }
        }
Пример #2
0
        public async void CreateTestOrder_UpdateWithWrongId__Returns_BadRequest()
        {
            var order = new Order
            {
                UserId        = Guid.NewGuid().ToString(),
                OrderProducts = new List <OrderProduct> {
                    new OrderProduct {
                        ProductId = 8, Quantity = 3
                    }
                },
                TotalPrice = 699.00M
            };

            using (var client = new TestClientProvider().Client)
            {
                var         payload = JsonSerializer.Serialize(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                var response = await client.PutAsync("/api/orders/update/" + Guid.NewGuid(), content);

                var deletedOrder = await client.DeleteAsync($"/api/orders/{order.Id}");

                Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
            }
        }
Пример #3
0
        public async Task UpdateOrderProductId_Return_NewOrderProductId()
        {
            using (var client = new TestClientProvider().Client)
            {
                var order        = _fixture.Order;
                var orderProduct = _fixture.OrderProduct;

                order.OrderProducts.Add(new OrderProduct {
                    ProductId = 7, Quantity = 3
                });

                var         payload = JsonSerializer.Serialize(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                var response = await client.PutAsync("/api/orders/update/" + order.Id, content);

                using (var responseStream = await response.Content.ReadAsStreamAsync())
                {
                    var updatedOrder = await JsonSerializer.DeserializeAsync <Order>(responseStream,
                                                                                     new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    await client.DeleteAsync("/api/orders/delete/" + updatedOrder.Id);

                    var actualProduct = updatedOrder.OrderProducts.Find(x => x.ProductId == 7);

                    Assert.Equal(7, actualProduct.ProductId);
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        public async Task DeleteSingleOrder_ShouldDeleteOrderFromList()
        {
            // Create Order to delete
            Order order = new Order
            {
                FirstName = "TestOrder",
                OrderDate = new DateTime(2020, 11, 09),
                Status    = Library.Models.OrderStatus.Delivered
            };

            using (var client = new TestClientProvider().Client)
            {
                var json    = JsonConvert.SerializeObject(order);
                var content = new StringContent(json, Encoding.UTF8, "application/json");
                var created = await client.PostAsync("api/order/AddOrder", content);

                string responseString = await created.Content.ReadAsStringAsync();

                var getOrder = JsonConvert.DeserializeObject <Order>(responseString);

                var delete = await client.DeleteAsync($"api/order/deletesingleorder?id={getOrder.Id}");

                Assert.Equal(HttpStatusCode.NoContent, delete.StatusCode);
            }
        }
Пример #6
0
        public async Task Delete_Order_EmptyGuid_returns_NotFound()
        {
            using (var client = new TestClientProvider().Client)
            {
                var deleteresponse = await client.DeleteAsync($"/api/orders/delete/{Guid.Empty}");

                Assert.Equal(HttpStatusCode.NotFound, deleteresponse.StatusCode);
            }
        }
Пример #7
0
        public async void Should_Delete_Existing_Batch()
        {
            using (var client = new TestClientProvider <TestStartup>().Client)
            {
                var response = await client.DeleteAsync($"/api/batches/{SeedData.FirstBatch.Id}");

                response.StatusCode.Should().Be(HttpStatusCode.OK);

                var testResponse = await client.GetAsync($"/api/batches/{SeedData.FirstBatch.Id}");

                testResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);
            }
        }
Пример #8
0
        public async Task DeleteProduct_Returns_Notfound()
        {
            using (var client = new TestClientProvider().Client)
            {
                var payload = JsonSerializer.Serialize(new Product.Service.Models.Product());

                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

                var response = await client.DeleteAsync($"/api/product/");

                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            }
        }
Пример #9
0
        public async void CreateTestOrder_Returns_OrderProduct()
        {
            var order = new Order
            {
                UserId        = Guid.NewGuid().ToString(),
                OrderProducts = new List <OrderProduct> {
                    new OrderProduct {
                        ProductId = 2, Quantity = 4
                    }
                },
                TotalPrice = 299.00M
            };

            using (var client = new TestClientProvider().Client)
            {
                var         payload = JsonSerializer.Serialize(order);
                HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");

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

                using (var responseStream = await response.Content.ReadAsStreamAsync())
                {
                    var updatedOrder = await JsonSerializer.DeserializeAsync <Order>(responseStream,
                                                                                     new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    await client.DeleteAsync("/api/orders/delete/" + updatedOrder.Id);

                    var orderProduct = updatedOrder.OrderProducts.FirstOrDefault();

                    Assert.IsType <OrderProduct>(orderProduct);
                }
                await client.DeleteAsync("/api/orders/delete/" + order.Id);
            }
        }
Пример #10
0
        public async void Dispose()
        {
            using (var client = new TestClientProvider().Client)
            {
                var deletedResponse = await client.DeleteAsync("/api/orders/delete/" + Order.Id);

                using (var responseStream = await deletedResponse.Content.ReadAsStreamAsync())
                {
                    var deletedId = await JsonSerializer.DeserializeAsync <Guid>(responseStream,
                                                                                 new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });
                }
            }
        }
Пример #11
0
        public async Task DeleteProduct_Returns_DeletedProductId()
        {
            using (var client = new TestClientProvider().Client)
            {
                //Create product
                var product = JsonSerializer.Serialize(new Product.Service.Models.Product()
                {
                    Name        = "TabortProdukt",
                    Quantity    = 10,
                    Price       = 100,
                    ImageUrl    = "https://www.stadshop.se/image/8171/648139.jpg",
                    Description = ""
                });

                HttpContent content = new StringContent(product, Encoding.UTF8, "application/json");

                var response = await client.PostAsync($"/api/product/createproduct", content);

                Product.Service.Models.Product newProduct = null;

                using (var responseStream = await response.Content.ReadAsStreamAsync())
                {
                    newProduct = await JsonSerializer.DeserializeAsync <Product.Service.Models.Product>(responseStream,
                                                                                                        new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });
                }

                //Delete product
                var deleteresponse = await client.DeleteAsync($"/api/product/DeleteProduct?productId={newProduct.Id}");

                using (var responseStream = await deleteresponse.Content.ReadAsStreamAsync())
                {
                    var deletedProduct = await JsonSerializer.DeserializeAsync <Product.Service.Models.Product>(responseStream,
                                                                                                                new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    Assert.Equal(newProduct.Id, deletedProduct.Id);
                }
            }
        }
Пример #12
0
        public async void Should_Return_Two_Stocks_When_Removing_One_Batch()
        {
            using (var client = new TestClientProvider <TestStartup>().Client)
            {
                var responseDelete = await client.DeleteAsync($"/api/batches/{SeedData.SecondBatch.Id}");

                responseDelete.StatusCode.Should().Be(HttpStatusCode.OK);

                var response = await client.GetAsync("/api/stocks");

                response.StatusCode.Should().Be(HttpStatusCode.OK);

                var stocks = JsonConvert.DeserializeObject <List <StockDTO> >(response.Content.ReadAsStringAsync().Result);

                Assert.Collection(stocks,
                                  dto => Assert.Equal(15, dto.Quantity),
                                  dto => Assert.Equal(22, dto.Quantity));
            }
        }
Пример #13
0
        public async Task DeleteOrder_Returns_DeletedId()
        {
            using (var client = new TestClientProvider().Client)
            {
                var orderId         = _fixture.Order.Id;
                var deletedResponse = await client.DeleteAsync("/api/orders/delete/" + orderId);

                using (var responseStream = await deletedResponse.Content.ReadAsStreamAsync())
                {
                    var deletedId = await JsonSerializer.DeserializeAsync <Guid>(responseStream,
                                                                                 new JsonSerializerOptions()
                    {
                        PropertyNameCaseInsensitive = true
                    });

                    Assert.Equal(orderId, deletedId);
                }
            }
        }
Пример #14
0
        public async Task UpdateSingleOrder_ShouldReturnUpdatedOrder()
        {
            Order order = new Order
            {
                FirstName = "TestOrder",
                OrderDate = new DateTime(2020, 11, 09),
                Status    = Library.Models.OrderStatus.Delivered
            };

            Order updatedOrder = new Order
            {
                FirstName = "UpdatedOrder",
                OrderDate = new DateTime(2020, 12, 12),
                Status    = Library.Models.OrderStatus.Refunded
            };

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

                var postResponse = await client.PostAsync("api/order/AddOrder", content);

                string postString = await postResponse.Content.ReadAsStringAsync();

                var getOrder = JsonConvert.DeserializeObject <Order>(postString);
                updatedOrder.Id = getOrder.Id;
                string upJson         = JsonConvert.SerializeObject(updatedOrder);
                var    updatedContent = new StringContent(upJson, Encoding.UTF8, "application/json");

                var updateResponse = await client.PutAsync($"api/order/UpdateSingleOrder?id={getOrder.Id}", updatedContent);

                await client.DeleteAsync($"api/order/deletesingleorder?id={updatedOrder.Id}");

                Assert.Equal(HttpStatusCode.NoContent, updateResponse.StatusCode);
            }
        }