public void ShoppingCart_AddingTwoIdentical()
        {
            // 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);
            ProductSellByWeight p2 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight);

            p2.productId   = 124;
            p2.productName = "Apple";
            p2.unitPrice   = 2.49m;
            p2.addWeight(1.3m);

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

            // assert
            const decimal expectedTotalPrice      = 2.49m * 3.7m;
            const int     expectedTotalItemNumber = 1;

            Assert.AreEqual(expectedTotalPrice, totalPrice);
            Assert.AreEqual(expectedTotalItemNumber, totalItemNumber);
        }
        public void ShoppingCart_AddingTwoIdenticalProductID_WithConflictedProductName()
        {
            // arrange
            ShoppingCart        shoppingCart       = new ShoppingCart();
            ProductSellFactory  productSellFactory = new ProductSellFactory();
            ProductSellByWeight p1 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight);

            p1.productId   = 124;
            p1.productName = "xxxx";
            p1.unitPrice   = 2.49m;
            p1.addWeight(2.4m);
            ProductSellByWeight p2 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight);

            p2.productId   = 124;
            p2.productName = "yyyy";
            p2.unitPrice   = 2.49m;
            p2.addWeight(1.3m);

            //act
            shoppingCart.add((ProductSell)p1);
            shoppingCart.add((ProductSell)p2);

            // assert
            //Must throw ArgumentOutOfRangeException : There is a conflict on the given ProductName.
        }
Esempio n. 3
0
        public void ShoppingCart_AddingTwoIdentical()
        {
            // arrange
            ShoppingCart          shoppingCart       = new ShoppingCart();
            ProductSellFactory    productSellFactory = new ProductSellFactory();
            ProductSellByQuantity p1 = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity);

            p1.productId   = 276;
            p1.productName = "Boxes of Cheerios";
            p1.unitPrice   = 6.99m;
            p1.addQuantity(2);
            ProductSellByQuantity p2 = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity);

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

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

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

            Assert.AreEqual(expectedTotalPrice, totalPrice);
            Assert.AreEqual(expectedTotalItemNumber, totalItemNumber);
        }
Esempio n. 4
0
        public void ShoppingCart_AddingTwoIdenticalProductID_WithConflictedUnitPrice()
        {
            // arrange
            ShoppingCart          shoppingCart       = new ShoppingCart();
            ProductSellFactory    productSellFactory = new ProductSellFactory();
            ProductSellByQuantity p1 = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity);

            p1.productId   = 276;
            p1.productName = "Boxes of Cheerios";
            p1.unitPrice   = 4.99m;
            p1.addQuantity(2);
            ProductSellByQuantity p2 = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity);

            p2.productId   = 276;
            p2.productName = "Boxes of Cheerios";
            p2.unitPrice   = 2.99m;
            p2.addQuantity(1);

            //act
            shoppingCart.add((ProductSell)p1);
            shoppingCart.add((ProductSell)p2);

            // assert
            //Must throw ArgumentOutOfRangeException : There is a conflict on the given UnitPrice.
        }
Esempio n. 5
0
        public void ShoppingCart_AddingInvalidEmptyProductSell()
        {
            // arrange
            ShoppingCart        shoppingCart       = new ShoppingCart();
            ProductSellFactory  productSellFactory = new ProductSellFactory();
            ProductSellByWeight p = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight);

            //act
            shoppingCart.add((ProductSell)p);

            // assert
            //Must throw ArgumentOutOfRangeException : productSell does not contain valid attributes
        }
Esempio n. 6
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);
        }
        public void ShoppingCartByCoupon_InValidTotalPriceDiscountThreshold()
        {
            // arrange
            ShoppingCartByCoupon shoppingCart       = new ShoppingCartByCoupon(new ShoppingCart(), -1, 100);
            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);

            //act
            shoppingCart.add((ProductSell)p1);
            decimal totalPrice      = shoppingCart.getTotalPrice();
            int     totalItemNumber = shoppingCart.getTotalItemNumber();
            // assert
            //Must throw ArgumentOutOfRangeException : DiscountCouponValue does not contain a valid value.
        }
        public void ShoppingCart_AddingTwoIdentical_PlusOneDiffrentOne()
        {
            // 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;
            ProductSellByQuantityInGroupSell p3 = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell);

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

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

            // assert
            const decimal expectedTotalPrice      = 6.99m * 5 + 12.99m * 2;
            const int     expectedTotalItemNumber = 2;

            Assert.AreEqual(expectedTotalPrice, totalPrice);
            Assert.AreEqual(expectedTotalItemNumber, totalItemNumber);
        }
        public void ShoppingCart_AddingSingle()
        {
            // arrange
            ShoppingCart        shoppingCart       = new ShoppingCart();
            ProductSellFactory  productSellFactory = new ProductSellFactory();
            ProductSellByWeight p = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight);

            p.productId   = 124;
            p.productName = "Apple";
            p.unitPrice   = 2.49m;
            p.addWeight(2.4m);

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

            // assert
            const decimal expectedTotalPrice = 2.49m * 2.4m;

            Assert.AreEqual(expectedTotalPrice, totalPrice);
        }
Esempio n. 10
0
        public void ShoppingCart_AddingSingle()
        {
            // arrange
            ShoppingCart          shoppingCart       = new ShoppingCart();
            ProductSellFactory    productSellFactory = new ProductSellFactory();
            ProductSellByQuantity p = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity);

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

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

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

            Assert.AreEqual(expectedTotalPrice, totalPrice);
        }