Esempio n. 1
0
        public void Calculate_Delivery_Cost()
        {
            var cart = BuildShoppingCart();
            var deliveryCostCalculator = new DeliveryCostCalculator(2, 3, 2.99);

            Assert.Equal(18.99, deliveryCostCalculator.CalculateFor(cart));
        }
        public double GetDeliveryCost()
        {
            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(8, 9);
            double deliveryCost = deliveryCostCalculator.CalculateFor(Cart);

            return(deliveryCost);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            IDeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(10, 150);

            Cart cart = new Cart(deliveryCostCalculator);

            Category food   = new Category("Food");
            Product  apple  = new Product("Apple", 100.0, food);
            Product  almond = new Product("Almonds", 150.0, food);

            Category telephone = new Category("Telephone");
            Product  note9     = new Product("Samsung Note 9", 5500.0, telephone);
            Product  iphone7   = new Product("Apple iPhone 7", 3500.0, telephone);

            cart.AddItem(apple, 3);
            cart.AddItem(almond, 1);
            cart.AddItem(note9, 1);
            cart.AddItem(iphone7, 1);

            Campaign campaign1 = new Campaign(food, 10, 1, DiscountType.Rate);
            Campaign campaign2 = new Campaign(food, 20, 1, DiscountType.Rate);

            cart.ApplyCampaigns(campaign1, campaign2);

            Coupon coupon1 = new Coupon(100, 10, DiscountType.Rate);

            cart.ApplyCoupon(coupon1);

            //Coupon coupon2 = new Coupon(500, 25, DiscountType.Amount);
            //cart.ApplyCoupon(coupon2);

            Console.WriteLine(cart.Print());
        }
        public void CalculateFor_Ensure_Calculate_For_Cart_Returns_True()
        {
            var deliveryCostCalculator = new DeliveryCostCalculator(_costPerDelivery, _costPerProduct, _fixedCost);

            // assert
            Assert.AreEqual(deliveryCostCalculator.CalculateFor(_cart), 6.79);
        }
Esempio n. 5
0
        static void Main()
        {
            var babyCategory       = new Category("Baby");
            var electronicCategory = new Category("Electronic");
            var tvCategory         = new Category("Tv", electronicCategory);
            var ledTvCategory      = new Category("Led Tv", tvCategory);

            var diaper    = new Product("Prima Diaper", 160, babyCategory);
            var toshibaTv = new Product("Toshiba Tv", 50, ledTvCategory);
            var samsungTv = new Product("Samsung UHD Tv", 250, tvCategory);

            var campaignForElectronic = new Campaign(electronicCategory, 5, 5, DiscountType.Rate);
            var campaignForLedTv      = new Campaign(ledTvCategory, 550, 1, DiscountType.Amount);

            IDeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(
                double.Parse(ConfigurationManager.AppSettings["CostPerDeliveryInTry"].Replace('.', ',')),
                double.Parse(ConfigurationManager.AppSettings["CostPerProductInTry"].Replace('.', ',')),
                double.Parse(ConfigurationManager.AppSettings["FixedCostInTry"].Replace('.', ',')));

            IShoppingCart cart = new Business.Objects.ShoppingCart(deliveryCostCalculator);

            cart.AddItem(diaper, 10);
            cart.AddItem(toshibaTv, 5);
            cart.AddItem(samsungTv, 1);

            cart.ApplyDiscounts(campaignForElectronic, campaignForLedTv);

            cart.ApplyCoupon(new Coupon(100, 400, DiscountType.Amount));

            Console.WriteLine(cart.Print());
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            do
            {
                Console.Write("Enter Weight in kg: ");
                var weight = Console.ReadLine();
                Console.Write("Enter Height in cm: ");
                var height = Console.ReadLine();
                Console.Write("Enter Width in cm: ");
                var width = Console.ReadLine();
                Console.Write("Enter Depth in cm: ");
                var depth = Console.ReadLine();

                var costCalculator = new DeliveryCostCalculator(new ParcelFactory(), new Validator());
                var result         = costCalculator.Calculate(weight, height, width, depth);
                if (!string.IsNullOrEmpty(result.Error))
                {
                    Console.WriteLine(result.Error);
                }
                else
                {
                    var cost = result.Cost > 0 ? "$" + result.Cost : "N/A";
                    Console.WriteLine("Category: " + result.Category);
                    Console.WriteLine("Cost: " + cost);
                }

                Console.WriteLine("Press ESC to stop or Enter to Calculate again");
                Console.WriteLine();
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
Esempio n. 7
0
        public CalculateModel(CalculateViewModel viewModel, DeliveryCostCalculator deliveryCostCalculator, IConfig config) : base(viewModel, config)
        {
            _deliveryCostCalculator = deliveryCostCalculator;

            ViewModel.Cost     = 0;
            ViewModel.Category = string.Empty;
        }
Esempio n. 8
0
        private void SetupData()
        {
            //cart printer sorts products by category. so we need predefined to prevent flaky tests
            var categoryID1 = Guid.Parse("BA38E701-024B-4968-ABED-510742481F0D");
            var category1   = new Category(categoryID1, Guid.NewGuid(), "Category 1");

            var categoryID2 = Guid.Parse("FD843460-7343-4C32-A2A8-493678AABA63");
            var category2   = new Category(categoryID2, Guid.NewGuid(), "Category 2");

            cart = new Cart(Guid.NewGuid());
            cart.AddItem(new Product(Guid.NewGuid(), "Title A", 100m, categoryID1), 3);
            cart.AddItem(new Product(Guid.NewGuid(), "Title B", 40m, categoryID2), 2);

            var campaign = new Campaign(Guid.NewGuid(), categoryID1, 1, DiscountType.Amount, 10m);

            cart.ApplyCampaign(campaign);

            var coupon = new Coupon(Guid.NewGuid(), 20m, DiscountType.Amount, 20m);

            cart.ApplyCoupon(coupon);

            var deliveryCostCalculator = new DeliveryCostCalculator(10m, 5m);
            var deliveryCost           = deliveryCostCalculator.CalculateFor(cart);

            cart.SetDeliveryCost(deliveryCost);

            categoryReader.Setup(r => r.GetByIDs(new List <Guid> {
                categoryID1, categoryID2
            }))
            .Returns(new List <Category> {
                category1, category2
            });

            printer = new CartPrinter(categoryReader.Object);
        }
Esempio n. 9
0
 public void Initialize()
 {
     _parcelFactoryMock = new Mock <IParcelFactory>();
     _parcelMock        = new Mock <IParcel>();
     _validatorMock     = new Mock <IValidator>();
     _calculator        = new DeliveryCostCalculator(_parcelFactoryMock.Object, _validatorMock.Object);
 }
Esempio n. 10
0
        static void Main(string[] args)
        {
            //lets add some examples
            var cart = new ShoppingCart();
            var deliveryCostCalculator = new DeliveryCostCalculator(2, 5, 3);

            var fruits = new Category("fruits");
            var cars   = new Category("cars");

            var apple  = new Product("apple", 5M, fruits);
            var orange = new Product("orange", 7M, fruits);

            var tofas = new Product("tofas", 5000m, cars);

            var campaign1 = new Campaign(fruits, 10, 2, DiscountType.Amount);
            var campaign2 = new Campaign(fruits, 0.9, 2, DiscountType.Rate);

            var coupon1 = new Coupon(1000M, 0.1, DiscountType.Rate);

            cart.AddItem(orange, 1);
            cart.AddItem(apple, 1);
            cart.AddItem(tofas, 2);

            cart.ApplyDiscounts(campaign1, campaign2);
            cart.ApplyCoupon(coupon1);

            //print all things
            Console.WriteLine(cart.Print(deliveryCostCalculator));
            Console.ReadKey();
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            Category category = new Category("Food");
            Product  banana   = new Product("Banana", 10, category);
            Product  apple    = new Product("Apple", 15, category);

            Category electronicCategory = new Category("Electronic");
            Product  samsung            = new Product("Samsung", 200, electronicCategory);
            Product  nokia = new Product("Nokia", 100, electronicCategory);

            CampaignFactory campaignFactory    = new CampaignFactory();
            AmountCampaign  campaignFood       = campaignFactory.ProduceCampaign(category, 25, 5, DiscountType.Amount) as AmountCampaign;
            AmountCampaign  campaignElectronic = campaignFactory.ProduceCampaign(electronicCategory, 50, 1, DiscountType.Amount) as AmountCampaign;

            DeliveryCostCalculator calculator = new DeliveryCostCalculator(1, 2, 2.99d);
            Cart shoppingCart = new Cart(calculator);

            shoppingCart.AddItem(banana, 8);
            shoppingCart.AddItem(apple, 5);
            shoppingCart.AddItem(samsung, 1);
            shoppingCart.AddItem(nokia, 2);
            shoppingCart.ApplyDiscounts(campaignFood, campaignElectronic);

            shoppingCart.Print();
        }
Esempio n. 12
0
        public void CreateCart()
        {
            Product apple  = new Product("Apple", 100.0, food);
            Product almond = new Product("Almonds", 150.0, food);


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


            // discounts rules can be 20% on a category if bought more than 3 items
            Campaign campaign1 = new Campaign(food, 20.0, DiscountType.Rate, 3);
            // another campaign rule 50% on category if bought more than 5 items
            Campaign campaign2 = new Campaign(food, 50.0, DiscountType.Rate, 5);
            // another campaign rule 5 TL amount discount on a category if bought more than 7 items
            Campaign campaign3 = new Campaign(food, 5.0, DiscountType.Amount, 7);

            // Cart should apply the maximum amount of discount to the cart.
            cart.ApplyDiscounts(campaign1, campaign2, campaign3);


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

            cart.ApplyCoupon(coupon);

            double fixedCost = 2.99;

            //i didn't understand costPerDelivery and costPerProduct value in documention that's why assign static value
            int costPerDelivery = 10;
            int costPerProduct  = 20;

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

            deliveryCostCalculator.CalculateFor(cart);
        }
Esempio n. 13
0
        public void Calculate_EmptyProduct_ReturnsException()
        {
            var deliveryCostCalculator = new DeliveryCostCalculator(2.5, 3.5);

            cart.Setup(x => x.GetDeliveryCount()).Returns(0);
            cart.Setup(x => x.GetProductCount()).Returns(0);
            Assert.Equal(2.99, deliveryCostCalculator.Calculate(cart.Object));
        }
Esempio n. 14
0
        public void CalculateFor_ShouldReturnFixedCost_When_CartIsEmpty()
        {
            calculator = new DeliveryCostCalculator(5, 10);
            shoppingCart.Setup(cart => cart.GetNumberOfDeliveries()).Returns(0);
            shoppingCart.Setup(cart => cart.GetNumberOfProducts()).Returns(0);

            Assert.Equal(CostConstants.FixedRate, calculator.CalculateFor(shoppingCart.Object));
        }
        public void CalculateFor_CartWithNoProduct_ReturnsFixedCost()
        {
            deliveryCostCalculator = new DeliveryCostCalculator(5, 10);
            cart.Setup(m => m.GetNumberOfDeliveries()).Returns(0);
            cart.Setup(m => m.GetNumberOfProducts()).Returns(0);

            Assert.That(deliveryCostCalculator.CalculateFor(cart.Object) == 2.99);
        }
Esempio n. 16
0
        public void DeliveryCostCalculatorShouldHaveCosts()
        {
            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(10.0, 5.0, 2.99);

            Assert.Equal(10.0, deliveryCostCalculator.CostPerDelivery);
            Assert.Equal(5.0, deliveryCostCalculator.CostPerProduct);
            Assert.Equal(2.99, deliveryCostCalculator.FixedCost);
        }
        public void Test_NoProducts()
        {
            deliveryCostCalculator = new DeliveryCostCalculator(3, 7);
            shoppingCart.Setup(m => m.GetNumberOfDeliveries()).Returns(0);
            shoppingCart.Setup(m => m.GetNumberOfProducts()).Returns(0);

            Assert.That(deliveryCostCalculator.CalculateFor(shoppingCart.Object) == 39);
        }
        public void DeliveryCostCalculatorTest_Constructor(decimal costPerDelivery, decimal costPerProduct, decimal fixedCost)
        {
            DeliveryCostCalculator deliveryCostCalculator = new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost);

            Assert.Equal(costPerDelivery, deliveryCostCalculator.costPerDelivery);
            Assert.Equal(costPerProduct, deliveryCostCalculator.costPerProduct);
            Assert.Equal(fixedCost, deliveryCostCalculator.fixedCost);
        }
Esempio n. 19
0
        public void Test_Calculate_For(double costPerDelivery, double costPerProduct, double fixedCost, Cart cart, double expectedCalculatedCost)
        {
            var deliveryCostCalculator = new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost);

            var calculatedCost = deliveryCostCalculator.CalculateFor(cart);

            //calculatedCost.ShouldBe(expectedCalculatedCost);
            throw new NotImplementedException(); //not implemented.Tests cases are not true, needs to be calculated
        }
        public void GetDeliveryCostTest_ShouldReturnZero_WhenCartIsEmpty(decimal costPerDelivery, decimal costPerProduct, decimal fixedCost)
        {
            ShoppingCart cart = new ShoppingCart();

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

            Assert.True(calculatedDeliveryCost == 0);
        }
Esempio n. 21
0
        public void Calculate_WhenShoppingCartWithNullProductListSupplied_ShouldThrowsArgumentNullException()
        {
            var shoppingCart = _fixture.Build <ShoppingCart>()
                               .Without(cart => cart.Products)
                               .Create();
            var deliveryCostCalculator = new DeliveryCostCalculator();

            Assert.Throws <ArgumentNullException>(() => deliveryCostCalculator.Calculate(shoppingCart));
        }
Esempio n. 22
0
        /// <summary>
        /// Calculate and returns delivery cost of product
        /// </summary>
        /// <returns>delivery cost of products</returns>
        public double GetDeliveryCost()
        {
            const double costPerDelivery        = 1.20;
            const double costPerProduct         = 1.30;
            const double fixedCost              = 2.99;
            var          deliveryCostCalculator = new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost);

            return(deliveryCostCalculator.CalculateFor(_shoppingCart));
        }
Esempio n. 23
0
        public void Calculate_NullCart_ReturnsArgumentNullException()
        {
            //Arrange
            deliveryCostCalculator = new DeliveryCostCalculator(2M, 6M);
            //Act

            //Assert
            Assert.Throws <ArgumentNullException>(() => deliveryCostCalculator.Calculate(null));
        }
        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);
        }
        public void CalculateFor_ShouldReturnExpectedCorrectDeliveryCalculation_WhenGivenCosts(double costPerDelivery, double costPerProduct, double fixedCost, double expected)
        {
            _deliveryCostCalculator = new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost);
            _shoppingCart.Setup(p => p.GetNumberOfDeliveries()).Returns(2);
            _shoppingCart.Setup(p => p.GetNumberOfProducts()).Returns(3);
            var result = _deliveryCostCalculator.CalculateFor(_shoppingCart.Object);

            Assert.True(expected == result);
        }
Esempio n. 26
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));
        }
        public void CalculateFor_CartWithOneDeliveryOneProduct_ReturnsValidCalculation()
        {
            deliveryCostCalculator = new DeliveryCostCalculator(5, 10);
            cart.Setup(m => m.GetNumberOfDeliveries()).Returns(1);
            cart.Setup(m => m.GetNumberOfProducts()).Returns(1);

            double expected = (5 * 1) + (10 * 1) + 2.99;

            Assert.That(deliveryCostCalculator.CalculateFor(cart.Object) == expected);
        }
        public void Should_Calculate()
        {
            DeliveryCostCalculator = new DeliveryCostCalculator(5, 10);

            var cart = new Cart(DeliveryCostCalculator);



            DeliveryCostCalculator.CalculateFor(cart).ShouldBe(2.99);
        }
Esempio n. 29
0
        public void CalculateFor_ShouldReturnValidCost_When_CartHasOneDeliveryAndOneProduct()
        {
            calculator = new DeliveryCostCalculator(5, 10);
            shoppingCart.Setup(cart => cart.GetNumberOfDeliveries()).Returns(1);
            shoppingCart.Setup(cart => cart.GetNumberOfProducts()).Returns(1);

            double expected = (5 * 1) + (10 * 1) + CostConstants.FixedRate;

            Assert.Equal(expected, calculator.CalculateFor(shoppingCart.Object));
        }
Esempio n. 30
0
        public void CalculateFor_WhenCalledWithNullParameter_ThrowsException()
        {
            //Arrange
            DeliveryCostCalculator calculator = new DeliveryCostCalculator(1, 2, 2.99d);

            //Act && Assert
            var exception = Assert.Throws <InvalidOperationException>(() => calculator.CalculateFor(null));

            Assert.Equal("There is no cart!", exception.Message);
        }