public void ShoppingCartWithDiscountWithFixedPriceBulkDiscountedLineItem2Test()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = true,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            LineItem lineItem = new FixedPriceLineItem
            {
                ProductId = 1,
                Name = "Cheerios (non GMO)",
                UnitPrice = 2.00m,
                Quantity = 10,
                IsDiscounted = true,
                DiscountThreshold = 4
            };
            shoppingCart.Add(lineItem);

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 15.00m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
        public void ShoppingCartWithOneByWeightPriceLineItemTest()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = false,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            LineItem lineItem = new ByWeightPriceLineItem
            {
                ProductId = 1,
                Name = "Apples",
                WeightInPounds = 2.00,
                PricePerPound = 2.00m
            };
            shoppingCart.Add(lineItem);

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 4.00m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
        public void ShoppingCartWithMixedLineItemsTest()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = true,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            List<LineItem> lineItemList = new List<LineItem>
            {
                // Fixed price line items

                new FixedPriceLineItem
                {
                    ProductId = 1,
                    Name = "Cheerios (non GMO)",
                    UnitPrice = 2.00m,
                    Quantity = 3,
                    IsDiscounted = true,
                    DiscountThreshold = 2
                },
                new FixedPriceLineItem
                {
                    ProductId = 2,
                    Name = "Milk",
                    UnitPrice = 3.00m,
                    Quantity = 2,
                    IsDiscounted = false
                },

                // By weight line items

                new ByWeightPriceLineItem
                {
                    ProductId = 3,
                    Name = "Apples",
                    PricePerPound = 1.00m,
                    WeightInPounds = 1.75
                },
                new ByWeightPriceLineItem
                {
                    ProductId = 4,
                    Name = "Oranges",
                    PricePerPound = 2.00m,
                    WeightInPounds = 1.50
                }
            };

            shoppingCart.Add(lineItemList);

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 13.75m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
        public void PrintShoppingCartTest()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = true,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            List<LineItem> lineItemList = new List<LineItem>
            {
                // Fixed price line items

                new FixedPriceLineItem
                {
                    ProductId = 1,
                    Name = "Cheerios (non GMO)",
                    UnitPrice = 2.00m,
                    Quantity = 3,
                    IsDiscounted = true,
                    DiscountThreshold = 2
                },
                new FixedPriceLineItem
                {
                    ProductId = 2,
                    Name = "Milk",
                    UnitPrice = 3.00m,
                    Quantity = 2,
                    IsDiscounted = false
                },

                // By weight line items

                new ByWeightPriceLineItem
                {
                    ProductId = 3,
                    Name = "Apples",
                    PricePerPound = 1.00m,
                    WeightInPounds = 1.75
                },
                new ByWeightPriceLineItem
                {
                    ProductId = 4,
                    Name = "Oranges",
                    PricePerPound = 2.00m,
                    WeightInPounds = 1.50
                }
            };

            shoppingCart.Add(lineItemList);

            //act
            string shoppingCartString = shoppingCart.ToString();

            // assert
            Assert.AreNotEqual(0, shoppingCartString.Length);
        }
        public void AddingNullItemToShoppingCartThrowsException1Test()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = false,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            //act
            shoppingCart.Add((LineItem)null);
        }
示例#6
0
        public static void Main()
        {
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = true,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            shoppingCart.Add(CreateLineItems());
            Console.WriteLine(shoppingCart.ToString());

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        public void EmptyShoppingCartHasZeroTotalPriceTest()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = false,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 0m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
        public void ShoppingCartSettersAndGettersTest()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = true,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            //act
            bool actualHasCoupon = shoppingCart.HasCoupon;
            decimal actualCouponTotalPriceThreshold = shoppingCart.CouponTotalPriceThreshold;
            decimal actualCouponDiscount = shoppingCart.CouponDiscount;

            // assert
            const bool expectedHasCoupon = true;
            const decimal expectedCouponTotalPriceThreshold = 10.00m;
            const decimal expectedCouponDiscount = 1.00m;

            Assert.AreEqual(expectedHasCoupon, actualHasCoupon);
            Assert.AreEqual(expectedCouponTotalPriceThreshold, actualCouponTotalPriceThreshold);
            Assert.AreEqual(expectedCouponDiscount, actualCouponDiscount);
        }
        public void ShoppingCartWithTwoByWeightPriceLineItems2Test()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = false,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            List<ByWeightPriceLineItem> byWeightPriceLineItemList = new List<ByWeightPriceLineItem>
            {
                new ByWeightPriceLineItem(productId : 1, name : "Apples", weightInPounds : 2.00, pricePerPound : 2.00m),
                new ByWeightPriceLineItem(productId : 1, name : "Apples", weightInPounds : 4.00, pricePerPound : 2.00m)
            };

            shoppingCart.Add(byWeightPriceLineItemList);

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 12.00m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
        public void ShoppingCartWithMultipleFixedPriceLineItems1Test()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = false,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            List<LineItem> lineItemList = new List<LineItem>
            {
                new FixedPriceLineItem
                {
                    ProductId = 1,
                    Name = "Cheerios (non GMO)",
                    UnitPrice = 2.00m,
                    Quantity = 1,
                    IsDiscounted = false
                },
                new FixedPriceLineItem
                {
                    ProductId = 1,
                    Name = "Cheerios (non GMO)",
                    UnitPrice = 2.00m,
                    Quantity = 1,
                    IsDiscounted = false
                },
                new FixedPriceLineItem
                {
                    ProductId = 1,
                    Name = "Cheerios (non GMO)",
                    UnitPrice = 2.00m,
                    Quantity = 1,
                    IsDiscounted = false
                },
                new FixedPriceLineItem
                {
                    ProductId = 1,
                    Name = "Cheerios (non GMO)",
                    UnitPrice = 2.00m,
                    Quantity = 1,
                    IsDiscounted = false
                }
            };

            shoppingCart.Add(lineItemList);

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 8.00m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
        public void ShoppingCartWithMultipleFixedPriceLineItems2Test()
        {
            // arrange
            ShoppingCart shoppingCart = new ShoppingCart
            {
                HasCoupon = false,
                CouponTotalPriceThreshold = 10.00m,
                CouponDiscount = 1.00m
            };

            List<LineItem> lineItemList = new List<LineItem>
            {
                new FixedPriceLineItem(productId : 1, name : "Cheerios (non GMO)", unitPrice : 2.00m, quantity : 1,isDiscounted : false, discountThreshold : 3),
                new FixedPriceLineItem(productId : 1, name : "Cheerios (non GMO)", unitPrice : 2.00m, quantity : 1, isDiscounted : false, discountThreshold : 3),
                new FixedPriceLineItem(productId : 1, name : "Cheerios (non GMO)", unitPrice : 2.00m, quantity : 1, isDiscounted : false, discountThreshold : 3),
                new FixedPriceLineItem(productId : 1, name : "Cheerios (non GMO)", unitPrice : 2.00m, quantity : 1, isDiscounted : false, discountThreshold : 3)
            };

            shoppingCart.Add(lineItemList);

            //act
            decimal actualTotalPrice = shoppingCart.GetTotalPrice();

            // assert
            const decimal expectedTotalPrice = 8.00m;
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }