コード例 #1
0
        public void CalculateForTest_ShouldReturnZero_WhenCartIsEmpty()
        {
            ShoppingCart cart = new ShoppingCart();

            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(2, 3, (decimal)2.99);
            decimal calculatedDeliveryCost = deliveryCostCalculator.calculateFor(cart);

            Assert.True(calculatedDeliveryCost == 0);
        }
コード例 #2
0
        public double getDeliveryCost()
        {
            double costPerDelivery = 2;
            double costPerProduct  = 1;
            double fixedCost       = Constants.FixedCost;

            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost);

            return(deliveryCostCalculator.calculateFor(this));
        }
コード例 #3
0
        public void CalculateFor_ShouldReturnDeliveryCost_WhenShoppingCartIsNotNull()
        {
            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(5, 4, 7);
            ShoppingCart           shoppingCart           = new ShoppingCart(deliveryCostCalculator);
            Category foodCategory = new Category("food");
            Product  apple        = new Product("Apple", 100.0, foodCategory);
            Product  almond       = new Product("Almonds", 150.0, foodCategory);

            shoppingCart.addItem(apple, 3);
            shoppingCart.addItem(almond, 1);
            var actual   = deliveryCostCalculator.calculateFor(shoppingCart);
            var expected = 20;

            Assert.Equal(expected, actual);
        }
コード例 #4
0
        public void CalculateForTest_ShouldReturnExpectedCost_WhenFormulaIsApplied(decimal costPerDelivery, decimal costPerProduct, decimal fixedCost, decimal expectedCost)
        {
            Category category = new Category("food");

            Product apple  = new Product("Apple", 100, category);
            Product almond = new Product("Almonds", 150, category);

            ShoppingCart cart = new ShoppingCart();

            cart.addItem(apple, 3);
            cart.addItem(almond, 1);

            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost);
            decimal calculatedDeliveryCost = deliveryCostCalculator.calculateFor(cart);

            Assert.True(expectedCost == calculatedDeliveryCost);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Category meyve = new Category("meyve");
            Category sebze = new Category("sebze");

            Product elma  = new Product("elma", 10, meyve);
            Product armut = new Product("armut", 10, meyve);
            Product saman = new Product("saman", 10, sebze);

            Cart basket = new Cart();

            basket.AddItem(elma, 10);
            basket.AddItem(saman, 10);
            basket.AddItem(armut, 10);

            //Console.WriteLine(meyve.Products.Count);
            //If more than 5 items on given category discount of 10
            Campaign campaign1 = new Campaign(meyve, 10.0, 5, DiscountType.Amount);
            Campaign campaign2 = new Campaign(sebze, 15.0, 2, DiscountType.Rate);
            Campaign campaign3 = new Campaign(meyve, 10.0, 50, DiscountType.Rate);


            basket.ApplyDiscounts(campaign1, campaign2, campaign3);

            Coupon coupon = new Coupon(100, 10, DiscountType.Amount);

            basket.ApplyDiscounts(coupon);

            //int x=  basket.GetNumberOfProducts();
            //Console.WriteLine("DISTINCT : " + x);
            //int y = basket.GetTotalNumberOfProducts();
            //Console.WriteLine("TOTAL : " + y);
            DeliveryCostCalculator dev = new DeliveryCostCalculator(2, 2, 3);

            dev.calculateFor(basket);


            basket.Print();



            Console.ReadLine(); //Pause
        }
コード例 #6
0
        public void Test_DeliveryCost()
        {
            //Arrange
            Category Fruit              = new Category("Fruit");
            Category Vegetable          = new Category("Vegetable");
            Product  Apple              = new Product("Apple", 100.0, Fruit);
            Product  Onion              = new Product("Onion", 50.0, Vegetable);
            Cart     cart               = new Cart();
            DeliveryCostCalculator dev  = new DeliveryCostCalculator(2, 2, 3);
            double expectedDeliveryCost = 11;

            //Act
            cart.AddItem(Apple, 5);
            cart.AddItem(Onion, 3);
            double actualDeliveryCost = dev.calculateFor(cart);

            //Assert
            Assert.AreEqual(expectedDeliveryCost, actualDeliveryCost);
        }
コード例 #7
0
        public void DeliveryCostCalculator_CalculateFor3Product_Returns()
        {
            var category = new Category("food");

            category.SubCategory = new List <Category>()
            {
                new Category("Sub1"), new Category("Sub2")
            };

            var product  = new Product("Apple", 100.0m, category.SubCategory[0]);
            var product3 = new Product("Banana", 50.0m, category.SubCategory[0]);
            var product2 = new Product("Almonds", 150.0m, category.SubCategory[1]);
            var cart     = new Cart("TestCart");

            cart.AddProduct(product, 3);
            cart.AddProduct(product3, 2);
            cart.AddProduct(product2, 5);

            DeliveryCostCalculator calculator = new DeliveryCostCalculator(1, 2, 3);
            var data = calculator.calculateFor(cart);

            Assert.That(data, Is.EqualTo(11));
        }
コード例 #8
0
        public void CalculateFor_ShouldThrowArgumentNullException_WhenShoppingCartIsNull()
        {
            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(1, 2, 3);

            Assert.Throws <ArgumentNullException>(() => deliveryCostCalculator.calculateFor(null));
        }