Beispiel #1
0
        public void TestCreateWithOrderProducts()
        {
            OrderLogic   logicO = new OrderLogic();
            ProductLogic logicP = new ProductLogic();

            try
            {
                OrderBinding model = new OrderBinding {
                    Id = 1, OrderProducts = new List <OrderProductBinding>()
                };
                model.OrderProducts.Add(new OrderProductBinding {
                    Count = 10, ProductId = 1
                });
                model.OrderProducts.Add(new OrderProductBinding {
                    Count = 13, ProductId = 2
                });
                logicP.Create(new ProductBinding {
                    Id = 1, Name = "0", Price = 10
                });
                logicP.Create(new ProductBinding {
                    Id = 2, Name = "1", Price = 5
                });
                logicO.Create(model);

                List <OrderView> list = logicO.Read(null);

                Assert.Equal(2, list[0].OrderProducts.Count);
                Assert.Equal(5, list[0].OrderProducts[1].Price);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
Beispiel #2
0
        public void TestReadSingle()
        {
            ProductLogic logic = new ProductLogic();

            try
            {
                ProductBinding model1 = new ProductBinding {
                    Name = "Test1", Price = 10
                };
                ProductBinding model2 = new ProductBinding {
                    Name = "Test2", Price = 20
                };
                logic.Create(model1);
                logic.Create(model2);

                List <ProductView> list = logic.Read(new ProductBinding {
                    Id = 1
                });

                Assert.Single(list);
                Assert.Equal(1, list[0].Id);
                Assert.Equal("Test1", list[0].Name);
                Assert.Equal(10, list[0].Price);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #3
0
        public void TestGetAllProducts()
        {
            ProductLogic logic = new ProductLogic();

            try
            {
                logic.Create(new ProductBinding {
                    Name = "Test1", Price = 10
                });
                logic.Create(new ProductBinding {
                    Name = "Test2", Price = 15
                });

                OrderProductPageDriver driver = new OrderProductPageDriver(new UiContext(new OrderLogic(), logic), new OrderView(), null);

                List <ProductView> list = driver.GetAllProducts();

                Assert.Equal(2, list.Count);
                Assert.Equal("Test1", list[0].Name);
                Assert.Equal(10, list[0].Price);
                Assert.Equal("Test2", list[1].Name);
                Assert.Equal(15, list[1].Price);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #4
0
        public void TestUpdateSeveralOPWithSameProductId()
        {
            OrderLogic   logicO = new OrderLogic();
            ProductLogic logicP = new ProductLogic();

            try
            {
                logicP.Create(new ProductBinding {
                    Name = "0"
                });
                logicP.Create(new ProductBinding {
                    Name = "1"
                });
                OrderBinding model = new OrderBinding {
                    OrderProducts = new List <OrderProductBinding>()
                };
                model.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1, Count = 3
                });
                logicO.Create(model);
                OrderView    ov     = logicO.Read(null)[0];
                OrderBinding model2 = new OrderBinding {
                    Id = ov.Id, OrderProducts = new List <OrderProductBinding>()
                };
                model2.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1, Count = 3
                });
                model2.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1, Count = 2
                });
                model2.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 2, Count = 1
                });
                model2.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 2, Count = 5
                });
                logicO.Update(model2);

                List <OrderView> list = logicO.Read(null);

                Assert.Equal(2, list[0].OrderProducts.Count);
                Assert.Equal(1, list[0].OrderProducts[0].ProductId);
                Assert.Equal(5, list[0].OrderProducts[0].Count);
                Assert.Equal(2, list[0].OrderProducts[1].ProductId);
                Assert.Equal(6, list[0].OrderProducts[1].Count);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
Beispiel #5
0
        public void TestIncorrectProductName()
        {
            List <string> messages = new List <string>();
            List <bool>   results  = new List <bool>();
            ProductLogic  logic    = new ProductLogic();

            try
            {
                logic.Create(new ProductBinding {
                    Name = "Ananas", Price = 87
                });
                ProductPageDriver driver = new ProductPageDriver(new UiContext(new OrderLogic(), logic), null);
                driver.ShowErrorMessage = (msg) => messages.Add(msg);

                driver.ProductName  = () => "Ananas";
                driver.ProductPrice = () => 87;
                results.Add(driver.SaveProduct());

                driver.ProductName  = () => " ";
                driver.ProductPrice = () => 87;
                results.Add(driver.SaveProduct());

                Assert.Equal(2, results.Count);
                Assert.False(results[0]);
                Assert.False(results[1]);
                Assert.Equal(2, messages.Count);
                Assert.Equal("Product with name Ananas already exist", messages[0]);
                Assert.Equal("Field name is empty", messages[1]);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #6
0
        public void TestMethodSaveUpdatedProduct()
        {
            string       message = "";
            ProductLogic logic   = new ProductLogic();

            try
            {
                logic.Create(new ProductBinding {
                    Name = "Ananas", Price = 87
                });
                ProductPageDriver driver = new ProductPageDriver(new UiContext(new OrderLogic(), logic), logic.Read(null)[0]);
                driver.ProductName     = () => "Banan";
                driver.ProductPrice    = () => 38;
                driver.ShowInfoMessage = (msg) => message = msg;

                bool result             = driver.SaveProduct();
                List <ProductView> list = logic.Read(null);

                Assert.True(result);
                Assert.Single(list);
                Assert.Equal("Banan", list[0].Name);
                Assert.Equal(38, list[0].Price);
                Assert.Equal("Product №1 was updated", message);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #7
0
        public void TestMethodSaveCreatedOrder()
        {
            string          message = "";
            OrderLogic      logicO  = new OrderLogic();
            ProductLogic    logicP  = new ProductLogic();
            OrderPageDriver driver  = new OrderPageDriver(new UiContext(logicO, logicP), null);

            driver.ShowInfoMessage = (msg) => { message = msg; };

            try
            {
                logicP.Create(new ProductBinding {
                    Price = 10
                });
                driver.MoveToOrderProductPage = (context, order, orderProduct) => order.OrderProducts.Add(new OrderProductView {
                    ProductId = 1
                });
                driver.AddOrderProduct();
                driver.AddOrderProduct();
                driver.AddOrderProduct();

                bool             result = driver.SaveOrder();
                List <OrderView> list   = logicO.Read(null);

                Assert.True(result);
                Assert.Single(list);
                Assert.Single(list[0].OrderProducts);
                Assert.Equal("Order was created", message);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
Beispiel #8
0
        public void TestGetSelectedProduct()
        {
            ProductLogic logic = new ProductLogic();

            try
            {
                logic.Create(new ProductBinding {
                    Name = "Test1", Price = 10
                });
                OrderProductView orderProduct = new OrderProductView {
                    ProductId = 1
                };

                OrderProductPageDriver driver   = new OrderProductPageDriver(new UiContext(new OrderLogic(), logic), new OrderView(), orderProduct);
                ProductView            product1 = driver.GetSelectedProduct();
                driver = new OrderProductPageDriver(new UiContext(new OrderLogic(), logic), new OrderView(), null);
                ProductView product2 = driver.GetSelectedProduct();

                Assert.Equal("Test1", product1.Name);
                Assert.Equal(10, product1.Price);
                Assert.Null(product2);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #9
0
        public void TestCreateSeveralOPWithSameProductId()
        {
            OrderLogic   logicO = new OrderLogic();
            ProductLogic logicP = new ProductLogic();

            try
            {
                OrderBinding model = new OrderBinding {
                    OrderProducts = new List <OrderProductBinding>()
                };
                model.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1, Count = 3
                });
                model.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1, Count = 2
                });
                logicP.Create(new ProductBinding {
                    Id = 1
                });
                logicO.Create(model);

                List <OrderView> list = logicO.Read(null);

                Assert.Single(list[0].OrderProducts);
                Assert.Equal(1, list[0].OrderProducts[0].ProductId);
                Assert.Equal(5, list[0].OrderProducts[0].Count);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
Beispiel #10
0
        public void TestDeleteOrderProducts()
        {
            OrderLogic   logicO = new OrderLogic();
            ProductLogic logicP = new ProductLogic();

            try
            {
                OrderBinding model1 = new OrderBinding {
                    Id = 1, OrderProducts = new List <OrderProductBinding>()
                };
                model1.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1
                });
                logicP.Create(new ProductBinding());
                logicO.Create(model1);
                logicO.Delete(model1);
                OrderBinding model2 = new OrderBinding {
                    Id = 1, OrderProducts = new List <OrderProductBinding>()
                };
                model2.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1
                });
                logicO.Create(model2);

                List <OrderView> list = logicO.Read(null);

                Assert.Single(list[0].OrderProducts);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
Beispiel #11
0
        public void TestOrderProductPrice()
        {
            OrderLogic   logicO = new OrderLogic();
            ProductLogic logicP = new ProductLogic();

            try
            {
                ProductBinding product = new ProductBinding {
                    Name = "Test", Price = 20
                };
                OrderBinding order = new OrderBinding {
                    OrderProducts = new List <OrderProductBinding>()
                };
                order.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1, Count = 2
                });
                logicP.Create(product);
                logicO.Create(order);

                List <OrderView> list = logicO.Read(null);

                Assert.Equal(20, list[0].OrderProducts[0].Price);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
Beispiel #12
0
        public void TestOrderProductAutoId()
        {
            OrderLogic   logicO = new OrderLogic();
            ProductLogic logicP = new ProductLogic();

            try
            {
                OrderBinding model1 = new OrderBinding {
                    Id = 1, OrderProducts = new List <OrderProductBinding>()
                };
                OrderBinding model2 = new OrderBinding {
                    Id = 1, OrderProducts = new List <OrderProductBinding>()
                };
                model1.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1
                });
                model1.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 2
                });
                model2.OrderProducts.Add(new OrderProductBinding {
                    ProductId = 1
                });
                logicP.Create(new ProductBinding {
                    Name = "0"
                });
                logicP.Create(new ProductBinding {
                    Name = "1"
                });
                logicO.Create(model1);
                logicO.Create(model2);

                List <OrderView> list = logicO.Read(null);

                Assert.Equal(1, list[0].OrderProducts[0].Id);
                Assert.Equal(2, list[0].OrderProducts[1].Id);
                Assert.Equal(3, list[1].OrderProducts[0].Id);
                Assert.Equal(1, list[0].OrderProducts[0].OrderId);
                Assert.Equal(1, list[0].OrderProducts[1].OrderId);
                Assert.Equal(2, list[1].OrderProducts[0].OrderId);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
        public IHttpActionResult Post(ProductBTO productBto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            ProductLogic categ = new ProductLogic();
            var          model = categ.Create(productBto);

            return(CreatedAtRoute("DefaultApi", new { id = model.id }, model));
        }
Beispiel #14
0
        public void TestCreateSameName()
        {
            ProductLogic logic   = new ProductLogic();
            string       message = "";

            try
            {
                ProductBinding model1 = new ProductBinding {
                    Name = "Test", Price = 10
                };
                logic.Create(model1);

                try
                {
                    ProductBinding model2 = new ProductBinding {
                        Name = "Test", Price = 10
                    };
                    logic.Create(model2);
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }

                List <ProductView> list = logic.Read(null);

                Assert.Single(list);
                Assert.Equal(1, list[0].Id);
                Assert.Equal("Test", list[0].Name);
                Assert.Equal(10, list[0].Price);
                Assert.Equal("Product with name Test already exist", message);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #15
0
        public void TestMethodDeleteProduct()
        {
            string       message = "";
            ProductLogic logic   = new ProductLogic();

            try
            {
                logic.Create(new ProductBinding {
                    Name = "Test1", Price = 10
                });
                logic.Create(new ProductBinding {
                    Name = "Test2", Price = 15
                });
                logic.Create(new ProductBinding {
                    Name = "Test3", Price = 23
                });
                ProductsPageDriver driver = new ProductsPageDriver(new UiContext(new OrderLogic(), logic));
                List <ProductView> list   = driver.GetAllProducts();
                driver.SelectedProduct = () => list[1];
                driver.ShowInfoMessage = (msg) => { message = msg; };

                driver.DeleteProduct();
                list = driver.GetAllProducts();

                Assert.Equal(2, list.Count);
                Assert.Equal("Test1", list[0].Name);
                Assert.Equal(10, list[0].Price);
                Assert.Equal("Test3", list[1].Name);
                Assert.Equal(23, list[1].Price);
                Assert.Equal("Product №2 was deleted", message);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #16
0
        public void TestDelete()
        {
            ProductLogic logic = new ProductLogic();

            try
            {
                ProductBinding model = new ProductBinding {
                    Name = "Test", Price = 10
                };
                logic.Create(model);
                logic.Delete(null);

                List <ProductView> list = logic.Read(null);

                Assert.Empty(list);
            }
            finally
            {
                logic.Delete(null);
            }
        }
Beispiel #17
0
        public void TestGetCount()
        {
            ProductLogic logic = new ProductLogic();

            try
            {
                logic.Create(new ProductBinding {
                    Name = "Test1", Price = 10
                });
                OrderProductView orderProduct = new OrderProductView {
                    ProductId = 1, Count = 10
                };

                OrderProductPageDriver driver = new OrderProductPageDriver(new UiContext(new OrderLogic(), logic), new OrderView(), orderProduct);
                int count = driver.GetCount();

                Assert.Equal(10, count);
            }
            finally
            {
                logic.Delete(null);
            }
        }