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);
            }
        }
        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);
            }
        }
        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);
            }
        }
Exemple #4
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (driver.SaveProduct())
     {
         Close();
     }
 }