public void ShoppingCart_AddingTwoIdentical()
        {
            // arrange
            ShoppingCart       shoppingCart       = new ShoppingCart();
            ProductSellFactory productSellFactory = new ProductSellFactory();
            ProductSellByQuantityInGroupSell p1   = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell);

            p1.productId   = 276;
            p1.productName = "Boxes of Cheerios";
            p1.unitPrice   = 6.99m;
            p1.addQuantity(3);
            p1.discountThreshold = 3;
            ProductSellByQuantityInGroupSell p2 = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell);

            p2.productId   = 276;
            p2.productName = "Boxes of Cheerios";
            p2.unitPrice   = 6.99m;
            p2.addQuantity(4);
            p2.discountThreshold = 3;

            //act
            shoppingCart.add((ProductSell)p1);
            shoppingCart.add((ProductSell)p2);
            decimal totalPrice      = shoppingCart.getTotalPrice();
            int     totalItemNumber = shoppingCart.getTotalItemNumber();

            // assert
            const decimal expectedTotalPrice      = 6.99m * 5;
            const int     expectedTotalItemNumber = 1;

            Assert.AreEqual(expectedTotalPrice, totalPrice);
            Assert.AreEqual(expectedTotalItemNumber, totalItemNumber);
        }
Esempio n. 2
0
        public void ProductSellByQuantityInGroupSell_SettersAndGetterTest()
        {
            // arrange
            ProductSellByQuantity productSellByQuantity = new ProductSellByQuantity
            {
                productId   = 276,
                productName = "Boxes of Cheerios",
                unitPrice   = 3m
            };

            productSellByQuantity.addQuantity(7);
            int actualDiscountThreshold = 3;
            ProductSellByQuantityInGroupSell productSellByQuantityInGroupSell = new ProductSellByQuantityInGroupSell(productSellByQuantity, actualDiscountThreshold);

            //act
            int     actualProductId   = productSellByQuantity.productId;
            string  actualProductName = productSellByQuantity.productName;
            decimal actualUnitPrice   = productSellByQuantity.unitPrice;
            int     actualQuantity    = productSellByQuantity.quantity;

            // assert
            const int     expectedProductId         = 276;
            const string  expectedProductName       = "Boxes of Cheerios";
            const decimal expectedUnitPrice         = 3m;
            const int     expectedQuantity          = 7;
            const int     expectedDiscountThreshold = 3;

            Assert.AreEqual(expectedProductId, actualProductId);
            Assert.AreEqual(expectedProductName, actualProductName);
            Assert.AreEqual(expectedUnitPrice, actualUnitPrice);
            Assert.AreEqual(expectedQuantity, actualQuantity);
            Assert.AreEqual(expectedDiscountThreshold, actualDiscountThreshold);
        }
Esempio n. 3
0
        public void ProductSellByQuantityInGroupSell_EmptyTest()
        {
            // arrange
            ProductSellByQuantityInGroupSell p = new ProductSellByQuantityInGroupSell(new ProductSellByQuantity(), 1);

            //act
            decimal price = p.getPrice();

            // assert
            Assert.AreEqual(0, price);
        }
Esempio n. 4
0
        public void ShoppingCart_RemoveProductSell()
        {
            // arrange
            ShoppingCart        shoppingCart       = new ShoppingCart();
            ProductSellFactory  productSellFactory = new ProductSellFactory();
            ProductSellByWeight p1 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight);

            p1.productId   = 124;
            p1.productName = "Apple";
            p1.unitPrice   = 2.49m;
            p1.addWeight(2.4m);
            ProductSellByQuantity p2 = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity);

            p2.productId   = 276;
            p2.productName = "Boxes of Cheerios";
            p2.unitPrice   = 6.99m;
            p2.addQuantity(4);
            ProductSellByQuantityInGroupSell p3 = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell);

            p3.productId   = 312;
            p3.productName = "Body Shampoo";
            p3.unitPrice   = 12.99m;
            p3.addQuantity(3);
            p3.discountThreshold = 3;
            ProductSellByQuantityInGroupSell p4 = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell);

            p4.productId   = 312;
            p4.productName = "Body Shampoo";
            p4.unitPrice   = 12.99m;
            p4.addQuantity(1);
            p4.discountThreshold = 3;

            //act
            shoppingCart.add((ProductSell)p1);
            shoppingCart.add((ProductSell)p2);
            shoppingCart.add((ProductSell)p3);
            shoppingCart.add((ProductSell)p4);
            shoppingCart.remove((ProductSell)p2);
            decimal totalPrice      = shoppingCart.getTotalPrice();
            int     totalItemNumber = shoppingCart.getTotalItemNumber();

            // assert
            const decimal expectedTotalPrice      = 2.49m * 2.4m + 12.99m * 3;
            const int     expectedTotalItemNumber = 2;

            Assert.AreEqual(expectedTotalPrice, totalPrice);
            Assert.AreEqual(expectedTotalItemNumber, totalItemNumber);
        }
Esempio n. 5
0
        public void ProductSellByQuantity_GiveZeroTo_DiscountThreshold()
        {
            // arrange
            ProductSellByQuantity p1 = new ProductSellByQuantity
            {
                productId   = 276,
                productName = "Boxes of Cheerios",
                unitPrice   = 3m,
            };

            p1.addQuantity(2);
            ProductSellByQuantityInGroupSell p2 = new ProductSellByQuantityInGroupSell(p1, 0);

            //act
            decimal price = p2.getPrice();

            // assert
            //Must throw ArgumentOutOfRangeException : DiscountThreshold does not contain a valid value.
        }
Esempio n. 6
0
        public void ProductSellByQuantity_DiscountPriceTest_Buy2Get1Free_4items()
        {
            // arrange
            ProductSellByQuantity p1 = new ProductSellByQuantity
            {
                productId   = 276,
                productName = "Boxes of Cheerios",
                unitPrice   = 3m
            };

            p1.addQuantity(4);
            ProductSellByQuantityInGroupSell p2 = new ProductSellByQuantityInGroupSell(p1, 3);

            //act
            decimal price = p2.getPrice();

            // assert
            const decimal expectedPrice = 3m * 3;

            Assert.AreEqual(expectedPrice, price);
        }
        public void ShoppingCart_AddingSingle()
        {
            // arrange
            ShoppingCart       shoppingCart       = new ShoppingCart();
            ProductSellFactory productSellFactory = new ProductSellFactory();
            ProductSellByQuantityInGroupSell p    = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell);

            p.productId   = 276;
            p.productName = "Boxes of Cheerios";
            p.unitPrice   = 6.99m;
            p.addQuantity(3);
            p.discountThreshold = 3;

            //act
            shoppingCart.add((ProductSell)p);
            decimal totalPrice = shoppingCart.getTotalPrice();

            // assert
            const decimal expectedTotalPrice = 6.99m * 2;

            Assert.AreEqual(expectedTotalPrice, totalPrice);
        }