Пример #1
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);
        }
Пример #2
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.
        }
        public void ProductSellByQuantity_SettersAndGetterTest()
        {
            // arrange
            ProductSellByQuantity productSellByQuantity = new ProductSellByQuantity
            {
                productId   = 276,
                productName = "Boxes of Cheerios",
                unitPrice   = 3m
            };

            productSellByQuantity.addQuantity(7);

            //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;

            Assert.AreEqual(expectedProductId, actualProductId);
            Assert.AreEqual(expectedProductName, actualProductName);
            Assert.AreEqual(expectedUnitPrice, actualUnitPrice);
            Assert.AreEqual(expectedQuantity, actualQuantity);
        }
Пример #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);
        }
Пример #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.
        }
        public void ProductSellByQuantity_PriceTest()
        {
            // arrange
            ProductSellByQuantity p = new ProductSellByQuantity
            {
                productId   = 276,
                productName = "Boxes of Cheerios",
                unitPrice   = 6.99m
            };

            p.addQuantity(2);

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

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

            Assert.AreEqual(expectedPrice, price);
        }
Пример #7
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);
        }
Пример #8
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);
        }