Exemplo n.º 1
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
                });

                ProductsPageDriver driver = new ProductsPageDriver(new UiContext(new OrderLogic(), logic));

                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);
            }
        }
Exemplo n.º 2
0
        public FormProducts(UiContext context)
        {
            InitializeComponent();

            driver = new ProductsPageDriver(context);

            ConfigureDriver();
        }
Exemplo n.º 3
0
        public void TestGetAllProductsEmpty()
        {
            ProductsPageDriver driver = new ProductsPageDriver(new UiContext(new OrderLogic(), new ProductLogic()));

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

            Assert.Empty(list);
        }
Exemplo n.º 4
0
        public void TestExceptionMoveToProductPage()
        {
            List <string>      messages = new List <string>();
            ProductsPageDriver driver   = new ProductsPageDriver(new UiContext(new OrderLogic(), new ProductLogic()));

            driver.MoveToProductPage = null;
            driver.ShowErrorMessage  = (msg) => { messages.Add(msg); };

            driver.AddProduct();

            Assert.Equal("Object reference not set to an instance of an object.", messages[0]);
        }
Exemplo n.º 5
0
        public void TestExceptionSelected()
        {
            List <string>      messages = new List <string>();
            ProductsPageDriver driver   = new ProductsPageDriver(new UiContext(new OrderLogic(), new ProductLogic()));

            driver.SelectedProduct  = () => (new List <ProductView>())[0];
            driver.ShowErrorMessage = (msg) => { messages.Add(msg); };

            driver.UpdateProduct();
            driver.DeleteProduct();

            Assert.Equal("Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')", messages[0]);
            Assert.Equal("Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')", messages[1]);
        }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        public void TestMethodMoveToProductPage()
        {
            string             message = "";
            ProductsPageDriver driver  = new ProductsPageDriver(new UiContext(new OrderLogic(), new ProductLogic()));

            driver.SelectedProduct   = () => new ProductView();
            driver.MoveToProductPage =
                (context, product) =>
            {
                if (product == null)
                {
                    message += "!";
                }
                else
                {
                    message += "~";
                }
            };

            driver.AddProduct();
            driver.UpdateProduct();

            Assert.Equal("!~", message);
        }