Exemple #1
0
        static void Main(string[] args)
        {
            ShopService shopService = new ShopService();

            var product   = shopService.AddNewProduct("Bow", 100, "Good bow");
            var property1 = shopService.GetProperty("Color", "Blue");
            var property2 = shopService.GetProperty("Size", "M");

            shopService.AddProperty(product, property1);
            shopService.AddProperty(product, property2);
            shopService.AddNewProduct(product);
            Console.WriteLine("hi");
            Console.ReadLine();
        }
        public void CheckAddProduct()
        {
            Mock <IProductRepository> repositoryMock = new Mock <IProductRepository>();
            ShopService ss = new ShopService(repositoryMock.Object);

            Product product = ss.AddNewProduct("Bow", 100, "Good for novice");

            repositoryMock.Verify(k => k.Insert(product), Times.Once());
        }
        public void AddNewProduct_WithValidProduct_ShouldHaveSameNameAsInputName()
        {
            // Arrange
            string      name        = "NewProduct";
            Category    category    = new Category("TestCategory");
            string      price       = "1";
            ShopService shopService = new ShopService();
            string      expected    = name;

            // Act
            shopService.AddNewProduct(name, category, price);

            // Assert
            string actual = shopService.ProductsInShop[shopService.ProductsInShop.Count - 1].Name;

            Assert.AreEqual(expected, actual, "Productname is not the same as entered in the inputfield!");
        }
        public void AddNewProduct_WithValidProduct_ShouldUpdateProductsList()
        {
            // Arrange
            string      name        = "NewProduct";
            Category    category    = new Category("TestCategory");
            string      price       = "1";
            ShopService shopService = new ShopService();
            int         expected    = shopService.ProductsInShop.Count + 1;

            // Act
            shopService.AddNewProduct(name, category, price);

            // Assert
            int actual = shopService.ProductsInShop.Count;

            Assert.AreEqual(expected, actual, "No product added");
        }
        private void BtnNewProductAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string   name     = txtNewProductName.Text;
                Category category = (Category)cmbNewProductCategory.SelectedItem;
                string   price    = txtNewProductPrice.Text;

                _shopService.AddNewProduct(name, category, price);

                FillProductListBox();
                ClearInputControls();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Fout!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void DeleteProduct_WithValidProduct_ShouldUpdateProductsList()
        {
            // Arrange
            ShopService shopService = new ShopService();

            for (int i = 0; i < 5; i++)
            {
                shopService.AddNewProduct($"test{i}", new Category("Test"), "100");
            }

            Product productToDelete = shopService.ProductsInShop[1];
            int     expected        = shopService.ProductsInShop.Count - 1;

            // Act
            shopService.DeleteProduct(productToDelete);

            // Assert
            int actual = shopService.ProductsInShop.Count;

            Assert.AreEqual(expected, actual, "Productlist has not been updated!");
        }
        public void AddNewProduct_PriceHasToBeANumber_ShouldThrowException()
        {
            // Arrange
            string      name        = "NewProduct";
            Category    category    = new Category("TestCategory");
            string      price       = "abc";
            ShopService shopService = new ShopService();

            try
            {
                // Act
                shopService.AddNewProduct(name, category, price);
            }
            catch (Exception ex)
            {
                // Assert
                StringAssert.Contains(ex.Message, ShopService.NewProductPriceIsWrongMessage);
                return;
            }

            Assert.Fail("No exeption was thrown");
        }
        public void AddNewProduct_PriceIsEmpty_ShouldThrowException()
        {
            // Arrange
            string      name        = "NewProduct";
            Category    category    = new Category("TestCategory");
            string      price       = "";
            ShopService shopService = new ShopService();

            try
            {
                // Act
                shopService.AddNewProduct(name, category, price);
            }
            catch (Exception ex)
            {
                // Assert
                StringAssert.Contains(ex.Message, ShopService.AllFieldsAreRequiredMessage);
                return;
            }

            Assert.Fail("No exeption was thrown");
        }
        public void AddNewProduct_PriceCannotBeMoreThanMaximumPrice_ShouldThrowException()
        {
            // Arrange
            string      name         = "NewProduct";
            Category    category     = new Category("TestCategory");
            decimal     maximumPrice = ShopService.MaximumPriceOfProduct;
            string      price        = (maximumPrice + 1).ToString();
            ShopService shopService  = new ShopService();

            try
            {
                // Act
                shopService.AddNewProduct(name, category, price);
            }
            catch (Exception ex)
            {
                // Assert
                StringAssert.Contains(ex.Message, ShopService.NewProductPriceIsWrongMessage);
                return;
            }

            Assert.Fail("No exeption was thrown");
        }