Exemplo n.º 1
0
        public void Run()
        {
            #region Get Delivery cost values from config.

            var costPerDelivery = _config.GetValue <double>("Delivery:CostPerDelivery");
            var costPerProduct  = _config.GetValue <double>("Delivery:CostPerProduct");
            var fixedCost       = _config.GetValue <double>("Delivery:FixedCost");

            #endregion

            #region Category and product creation

            var computerCategory = new Category.Category("Computer");
            var phoneCategory    = new Category.Category("Phone");

            var ipone   = new Iphone(7500, phoneCategory);
            var macbook = new Macbook(18500, computerCategory);

            #endregion

            #region Shopping cart creation

            IShoppingCart cart = new Cart.ShoppingCart(new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost));
            cart.AddItem(ipone, 10);
            cart.AddItem(macbook, 5);

            #endregion

            #region Get campaign type from CampaignFactory with CampaignTypes enum.

            CampaignFactory campaignFactory = new CampaignFactory();
            var             campaign2       = campaignFactory.Get(computerCategory, 1500, 1, CampaignTypes.Amount);
            var             campaign3       = campaignFactory.Get(phoneCategory, 2, 1, CampaignTypes.Rate);

            #endregion

            #region Apply first campaign discount then coupon

            cart.ApplyDiscounts(campaign2, campaign3);

            CouponFactory couponFactory = new CouponFactory();
            var           coupon        = couponFactory.Get(500, 150, CouponTypes.Amount);

            cart.ApplyCoupon(coupon);

            #endregion

            Console.WriteLine(cart.Print());

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void AddItem_ShouldArgumentOutOfRangeException_WhenQuantityIsLessThanOrEqualZero(int quantity)
        {
            _shoppingCart = new ShoppingCart.Cart.ShoppingCart(_deliveryCostCalculator.Object);

            ShoppingCart.Product.Iphone iphone = new ShoppingCart.Product.Iphone(1200, new Category.Category("Category1"));

            Assert.Throws <ArgumentOutOfRangeException>(() => _shoppingCart.AddItem(iphone, quantity));
        }
Exemplo n.º 3
0
        public void GetNumberOfDifferentProducts_ShouldReturnTwo_WhenDistinctProductCountIsTwo()
        {
            _shoppingCart = new ShoppingCart.Cart.ShoppingCart(_deliveryCostCalculator.Object);

            ShoppingCart.Product.Iphone  iphone1  = new ShoppingCart.Product.Iphone(1200, new Category.Category("c1"));
            ShoppingCart.Product.Iphone  iphone2  = new ShoppingCart.Product.Iphone(1200, new Category.Category("c123"));
            ShoppingCart.Product.Macbook macbook1 = new ShoppingCart.Product.Macbook(1200, new Category.Category("x1"));
            ShoppingCart.Product.Macbook macbook2 = new ShoppingCart.Product.Macbook(1200, new Category.Category("x2"));


            _shoppingCart.AddItem(iphone1, 1);
            _shoppingCart.AddItem(iphone2, 1);
            _shoppingCart.AddItem(macbook1, 1);
            _shoppingCart.AddItem(macbook2, 1);

            var numberOfProducts = _shoppingCart.GetNumberOfDifferentProducts();

            Assert.True(numberOfProducts == 2);
        }
Exemplo n.º 4
0
        public void GetNumberOfDeliveries_ShouldReturnTwo_WhenDistinctCategoryCountIsTwo()
        {
            _shoppingCart = new ShoppingCart.Cart.ShoppingCart(_deliveryCostCalculator.Object);

            ShoppingCart.Product.Iphone iphone1 = new ShoppingCart.Product.Iphone(1200, new Category.Category("c1"));
            ShoppingCart.Product.Iphone iphone2 = new ShoppingCart.Product.Iphone(1200, new Category.Category("c123"));
            ShoppingCart.Product.Iphone iphone3 = new ShoppingCart.Product.Iphone(1200, new Category.Category("c1"));
            ShoppingCart.Product.Iphone iphone4 = new ShoppingCart.Product.Iphone(1200, new Category.Category("c1"));


            _shoppingCart.AddItem(iphone1, 1);
            _shoppingCart.AddItem(iphone2, 1);
            _shoppingCart.AddItem(iphone3, 1);
            _shoppingCart.AddItem(iphone4, 1);

            var numberOfDeliveries = _shoppingCart.GetNumberOfDeliveries();

            Assert.True(numberOfDeliveries == 2);
        }
Exemplo n.º 5
0
 public void AddItem_ShouldArgumentNullException_WhenProductIsNull()
 {
     _shoppingCart = new ShoppingCart.Cart.ShoppingCart(_deliveryCostCalculator.Object);
     Assert.Throws <ArgumentNullException>(() => _shoppingCart.AddItem(null, 1));
 }