コード例 #1
0
        public void ReturnMostExpensiveProduct()
        {
            string  name     = "Butter";
            int     quantity = 10;
            decimal price    = 100m;

            string  name2     = "Bread";
            int     quantity2 = 5;
            decimal price2    = 150m;

            string  name3     = "Meat";
            int     quantity3 = 10;
            decimal price3    = 200m;

            Product product  = new Product(name, quantity, price);
            Product product2 = new Product(name2, quantity2, price2);
            Product product3 = new Product(name3, quantity3, price3);

            StoreManager manager = new StoreManager();

            manager.AddProduct(product);
            manager.AddProduct(product2);
            manager.AddProduct(product3);

            List <Product> orderedProducts       = manager.Products.OrderByDescending(x => x.Price).ToList();
            Product        expectedMostExpensive = orderedProducts[0];
            Product        actualMostExpensive   = manager.GetTheMostExpensiveProduct();

            Assert.That(actualMostExpensive.Price == expectedMostExpensive.Price);
            Assert.That(actualMostExpensive.Name == expectedMostExpensive.Name);
            Assert.That(actualMostExpensive.Quantity == expectedMostExpensive.Quantity);
        }
コード例 #2
0
        public void AddProductShgouldThrowNullExceptionWhenAddingNullProduct()
        {
            StoreManager sm      = new StoreManager();
            Product      product = new Product("Lenovo", 100, 1500.50m);

            sm.AddProduct(product);

            Assert.Throws <ArgumentNullException>(() => sm.AddProduct(null));
        }
コード例 #3
0
        public void Add_Product_Should_Throw_An_Exception_If_The_Product_Quantity_Is_Bellow_Zero()
        {
            var storeManager = new StoreManager();

            storeManager.AddProduct(new Product("Pizza", 10, 0.1m));

            Assert.Throws <ArgumentException>(
                () => storeManager.AddProduct(new Product("Pizza", -10, 0.1m)),
                "The product qty is not bellow zero.");
        }
コード例 #4
0
        public void Add_Product_Should_Throw_An_Exception_If_The_Product_Is_Null()
        {
            var storeManager = new StoreManager();

            storeManager.AddProduct(new Product("Pizza", 10, 0.1m));

            Assert.Throws <ArgumentNullException>(
                () => storeManager.AddProduct(null),
                "The product is not null.");
        }
コード例 #5
0
        public void BuyProductShgouldThrowExcQuantity()
        {
            StoreManager sm       = new StoreManager();
            Product      product  = new Product("Lenovo", 100, 1500.50m);
            Product      product2 = new Product("Lenovoooooo", 100000, 150000.50m);

            sm.AddProduct(product);
            sm.AddProduct(product2);

            Assert.Throws <ArgumentException>(() => sm.BuyProduct("Lenovo", 10000000));
        }
コード例 #6
0
        public void BuyProductQuantityBeCorrect()
        {
            StoreManager sm       = new StoreManager();
            Product      product  = new Product("Lenovo", 100, 1500m);
            Product      product2 = new Product("Lenovoooooo", 100000, 150000.50m);

            sm.AddProduct(product);
            sm.AddProduct(product2);

            sm.BuyProduct("Lenovo", 50);

            Assert.AreEqual(50, product.Quantity);
        }
コード例 #7
0
        public void ReturnMostExpensiveProduct()
        {
            StoreManager manager  = new StoreManager();
            Product      product  = new Product("Test", 20, 10);
            Product      product1 = new Product("Test1", 30, 20);

            manager.AddProduct(product);
            manager.AddProduct(product1);

            var topProduct = manager.GetTheMostExpensiveProduct();

            Assert.AreSame(product1, topProduct);
        }
コード例 #8
0
        public void BuyProductShouldReturnCorrectProduct()
        {
            StoreManager sm       = new StoreManager();
            Product      product  = new Product("Lenovo", 100, 1500m);
            Product      product2 = new Product("Lenovoooooo", 100000, 150000.50m);

            sm.AddProduct(product);
            sm.AddProduct(product2);

            sm.BuyProduct("Lenovo", 50);

            Assert.AreEqual("Lenovo", product.Name);
        }
コード例 #9
0
        public void GetTMEProductShouldReturnCorrectProduct()
        {
            StoreManager sm       = new StoreManager();
            Product      product  = new Product("Lenovo", 100, 1m);
            Product      expected = new Product("Lenovoooooo", 100000, 100m);

            sm.AddProduct(product);
            sm.AddProduct(expected);

            Product actual = sm.GetTheMostExpensiveProduct();

            Assert.AreEqual(expected, actual);
        }
コード例 #10
0
        public void TestLastMethod()
        {
            var product  = new Product("Pesho", 5, 15.5m);
            var product1 = new Product("Gosho", 5, 5.5m);

            var store = new StoreManager();

            store.AddProduct(product);
            store.AddProduct(product1);

            var producto = store.Products.OrderByDescending(p => p.Price).First();

            Assert.AreEqual(producto, store.GetTheMostExpensiveProduct());
        }
コード例 #11
0
        public void Get_Most_Expensive_Product_Should_Return_The_Correct_Product()
        {
            var storeManager = new StoreManager();

            storeManager.AddProduct(new Product("Pizza", 10, 0.1m));
            storeManager.AddProduct(new Product("Salami", 101, 0.5m));
            storeManager.AddProduct(new Product("Ham", 120, 1m));
            storeManager.AddProduct(new Product("Coke", 104, 3m));

            var product = storeManager.GetTheMostExpensiveProduct();

            Assert.That(product.Name, Is.EqualTo("Coke"));
            Assert.That(product.Quantity, Is.EqualTo(104));
            Assert.That(product.Price, Is.EqualTo(3));
        }
コード例 #12
0
        public void GetTheMostExpensiveProductShouldWork()
        {
            StoreManager storeManager = new StoreManager();
            Product      product      = new Product("produkt", 3, 2.50m);
            Product      product2     = new Product("produkt2", 3, 12.50m);
            Product      product3     = new Product("produkt3", 3, 6.50m);

            storeManager.AddProduct(product);
            storeManager.AddProduct(product2);
            storeManager.AddProduct(product3);

            var mostExpensiveProduct = storeManager.GetTheMostExpensiveProduct();

            Assert.AreEqual(product2, mostExpensiveProduct);
        }
コード例 #13
0
        public void AddNullProductShouldThrowException()
        {
            StoreManager manager = new StoreManager();

            Assert.Throws <ArgumentNullException>(()
                                                  => manager.AddProduct(null));
        }
コード例 #14
0
        public void MethodGetTheMostExpensiveProductShouldReturnMostExpensiveProduct()
        {
            //Arrange
            StoreManager storeManager = new StoreManager();
            Product      product      = new Product("Product", 20, 50);
            Product      product2     = new Product("Product2", 20, 100);

            //Act
            storeManager.AddProduct(product);
            storeManager.AddProduct(product2);
            Product expectedResult = product2;
            Product actualResult   = storeManager.GetTheMostExpensiveProduct();

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
コード例 #15
0
        public ActionResult AddProduct(EditProduct product)
        {
            var newproduct = _manage.AddProduct(_manage.ToProduct(product));

            _manage.SaveProductImage(product, newproduct.ProductId);
            return(RedirectToAction("Details", "Store", new { id = newproduct.ProductId }));
        }
コード例 #16
0
        public void AddCorrectProductShouldWork()
        {
            StoreManager storeManager = new StoreManager();
            Product      product      = new Product("produkt", 2, 2.50m);

            storeManager.AddProduct(product);
            Assert.Contains(product, (System.Collections.ICollection)storeManager.Products);
        }
コード例 #17
0
        public void AddProductShgouldThrowNullExceptionWhenAddingNegativeQuantity()
        {
            StoreManager sm      = new StoreManager();
            Product      product = new Product("Lenovo", -100, 1500.50m);


            Assert.Throws <ArgumentException>(() => sm.AddProduct(product));
        }
コード例 #18
0
        public void Add_Product_Should_Add_Product_Correctly()
        {
            var storeManager = new StoreManager();

            storeManager.AddProduct(new Product("Pizza", 10, 0.1m));

            Assert.That(storeManager.Count, Is.EqualTo(1));
        }
コード例 #19
0
        public void BuyingShouldCalculateProperly()
        {
            StoreManager manager  = new StoreManager();
            Product      product  = new Product("Test", 20, 10);
            Product      product1 = new Product("Test1", 30, 20);

            manager.AddProduct(product);
            manager.AddProduct(product1);

            manager.BuyProduct("Test", 20);

            var expectedTotalQuantity = 0;
            var expectedFinalPrice    = 0;

            Assert.AreEqual(expectedTotalQuantity, product.Quantity);
            Assert.AreEqual(expectedFinalPrice, product.Quantity * product.Price);
        }
コード例 #20
0
        public void AddBelowZeroQuantityProductShouldThrowException()
        {
            StoreManager manager = new StoreManager();
            Product      product = new Product("Test", -20, 10);

            Assert.Throws <ArgumentException>(()
                                              => manager.AddProduct(product));
        }
コード例 #21
0
 public void AddProductShouldThrownExceptionWhenTryToAddNullProduct()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         _storeManager.AddProduct(null);
     });
 }
コード例 #22
0
        public void AddNullProductWithNegativeQtyShouldThrowException()
        {
            StoreManager storeManager = new StoreManager();

            Assert.Throws <ArgumentException>(() =>
            {
                storeManager.AddProduct(new Product("produkt", -20, 2.50m));
            }, "Product count can't be below or equal to zero.");
        }
コード例 #23
0
        public void ManagerConstructorWorksCorrectly()
        {
            StoreManager sm      = new StoreManager();
            Product      product = new Product("Lenovo", 100, 1500.50m);

            sm.AddProduct(product);

            Assert.AreEqual(1, sm.Count);
        }
コード例 #24
0
        public void AddCorrectProductShouldAddProduct()
        {
            StoreManager storeManager = new StoreManager();
            Product      product      = new Product("produkt", 2, 2.50m);

            storeManager.AddProduct(product);

            Assert.AreEqual(storeManager.Count, 1);
        }
コード例 #25
0
        public void TestAsReadOnly()
        {
            var product = new Product("Pesho", 5, 5.5m);
            var store   = new StoreManager();

            store.AddProduct(product);

            Assert.AreEqual(1, store.Products.Count);
        }
コード例 #26
0
        public void StoreManagerBuyProductCorrect()
        {
            Product      productToBuy = new Product("Z", 5, 1);
            StoreManager manager      = new StoreManager();

            manager.AddProduct(productToBuy);
            manager.BuyProduct(productToBuy.Name, 1);
            Assert.AreEqual(4, productToBuy.Quantity);
        }
コード例 #27
0
        public void TestConstructor()
        {
            var product = new Product("Pesho", 5, 5.5m);
            var store   = new StoreManager();

            store.AddProduct(product);

            Assert.AreEqual(1, store.Count);
        }
コード例 #28
0
        public void TestAddNullException()
        {
            var store = new StoreManager();

            Assert.Throws <ArgumentNullException>(() =>
            {
                store.AddProduct(null);
            });
        }
コード例 #29
0
        public void TestAddNegativeQuantityException()
        {
            var product = new Product("Pesho", -5, 5.5m);
            var store   = new StoreManager();

            Assert.Throws <ArgumentException>(() =>
            {
                store.AddProduct(product);
            });
        }
コード例 #30
0
        public void MethodAddProductShouldThrowExceptionIfProductQuantityIsZeroOrBelow(int quantity)
        {
            //Arrange
            StoreManager storeManager = new StoreManager();
            Product      product      = new Product("Product", quantity, 50);

            //Act - Assert
            Assert.Throws <ArgumentException>(()
                                              => storeManager.AddProduct(product));
        }