Esempio n. 1
0
        public async void Should_Update_Existing_Batch()
        {
            using (var client = new TestClientProvider <TestStartup>().Client)
            {
                var updateBatch = new BatchForUpdate
                {
                    FruitId   = SeedData.RaspberryErikaFruit.Id,
                    VarietyId = SeedData.RaspberryErikaFruit.Variety.Id,
                    Quantity  = 25
                };

                var json = JsonConvert.SerializeObject(updateBatch);

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

                var response = await client.PutAsync($"/api/batches/{SeedData.FirstBatch.Id}", content);

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

                var batch = JsonConvert.DeserializeObject <BatchDTO>(response.Content.ReadAsStringAsync().Result);

                Assert.Equal(SeedData.FirstBatch.Id, batch.Id);
                Assert.Equal(updateBatch.FruitId, batch.FruitId);
                Assert.Equal(updateBatch.VarietyId, batch.VarietyId);
                Assert.Equal(updateBatch.Quantity, batch.Quantity);
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        public async Task UpdateProduct_Returns_OK()
        {
            using (var client = new TestClientProvider().Client)
            {
                var product1 = new Product.Service.Models.Product()
                {
                    Id = 1, Price = 50, Quantity = 10
                };
                var product2 = new Product.Service.Models.Product()
                {
                    Id = 2, Price = 75, Quantity = 15
                };

                var cartItems = new List <Product.Service.Models.CartItem>()
                {
                    new Product.Service.Models.CartItem()
                    {
                        Product = product1, Quantity = 1
                    },
                    new Product.Service.Models.CartItem()
                    {
                        Product = product2, Quantity = 2
                    }
                };

                var payload = JsonSerializer.Serialize(new Product.Service.Models.ShoppingCart()
                {
                    cartItems = cartItems
                }
                                                       );

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

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

                using (var responseStream = await response.Content.ReadAsStreamAsync())
                {
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
            }
        }
Esempio n. 5
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);
            }
        }