コード例 #1
0
        public void TestOrderProductUndefinedName()
        {
            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);
                logicP.Delete(new ProductBinding {
                    Id = 1
                });

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

                Assert.Equal("Undefined", list[0].OrderProducts[0].ProductName);
            }
            finally
            {
                logicO.Delete(null);
                logicP.Delete(null);
            }
        }
コード例 #2
0
ファイル: ProductLogicTest.cs プロジェクト: NeaEnot/GUIDT
        public void TestDeleteSingle()
        {
            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);
                logic.Delete(new ProductBinding {
                    Id = 2
                });

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

                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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        public void TestIncorrectPrice()
        {
            List <string> messages = new List <string>();
            List <bool>   results  = new List <bool>();
            ProductLogic  logic    = new ProductLogic();

            try
            {
                ProductPageDriver driver = new ProductPageDriver(new UiContext(new OrderLogic(), logic), null);
                driver.ShowErrorMessage = (msg) => messages.Add(msg);

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

                driver.ProductName  = () => "Banan";
                driver.ProductPrice = () => - 1;
                results.Add(driver.SaveProduct());

                Assert.Equal(2, results.Count);
                Assert.False(results[0]);
                Assert.False(results[1]);
                Assert.Equal(2, messages.Count);
                Assert.Equal("Incorrect price", messages[0]);
                Assert.Equal("Incorrect price", messages[1]);
            }
            finally
            {
                logic.Delete(null);
            }
        }
コード例 #6
0
ファイル: ProductController.cs プロジェクト: SpokyOky/PIS_CW
 public IActionResult Delete(int id)
 {
     _productLogic.Delete(new Product {
         Id = id
     });
     return(RedirectToAction("Index"));
 }
コード例 #7
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);
            }
        }
コード例 #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);
            }
        }
コード例 #9
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);
            }
        }
コード例 #10
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);
            }
        }
コード例 #11
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);
            }
        }
コード例 #12
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);
            }
        }
コード例 #13
0
ファイル: ProductLogicTest.cs プロジェクト: NeaEnot/GUIDT
        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);
            }
        }
コード例 #14
0
 public ActionResult DeleteApplicantEducation([FromBody] ProductPoco[] pocos)
 {
     try
     {
         _logic.Delete(pocos);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
コード例 #15
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);
            }
        }
コード例 #16
0
        public IHttpActionResult Delete(int id)
        {
            {
                if (id <= 0)
                {
                    return(BadRequest("Not a valid category id"));
                }

                ProductLogic categ = new ProductLogic();
                categ.Delete(id);

                return(Ok("This category is deleted"));
            }
        }
コード例 #17
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);
            }
        }
コード例 #18
0
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        EmployeeLogic el = new EmployeeLogic();
        Employee      e2 = el.SelectByID(Convert.ToInt32(Session["EmployeeID"]));

        if (!(e2.Designation.Equals("STOCK MANAGER") || e2.Designation.Equals("STOCK EMPLOYEE") || e2.Designation.Equals("EMPLOYEE") || e2.Designation.Equals("ACCOUNTATANT") || e2.Designation.Equals("HR MANAGER") || e2.Designation.Equals("HR EMPLOYEE")))
        {
            ProductLogic pl = new ProductLogic();
            Product      p1 = pl.SelectByProductID(Convert.ToInt32(e.CommandArgument));
            if (p1 != null)
            {
                int i = pl.Delete(p1.ProductID);

                Response.Redirect("ProdList.aspx");
            }
        }
        else
        {
            Response.Redirect("Access.aspx");
        }
    }
コード例 #19
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);
            }
        }
コード例 #20
0
ファイル: ProductLogicTest.cs プロジェクト: NeaEnot/GUIDT
        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);
            }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
 public ActionResult DeleteProduct(
     [FromBody] ProductPoco[] pocos)
 {
     _logic.Delete(pocos);
     return(Ok());
 }