Пример #1
0
        public IExpensesCalculator GetExpensesCalculatorThatHaveDiscountFromMedicine()
        {
            IShoppingBag shoppingBag = GetShoppingBag(1, 450);
            IEnumerable <IDiscountor> discountors = GetDiscountors(60, shoppingBag);

            return(GetExpensesCalculator(shoppingBag, discountors));
        }
Пример #2
0
 protected Tuple <bool, string> validate(IShoppingBag <string> bag, IDiscount discount)
 {
     if (discount == null)
     {
         return(new Tuple <bool, string>(false, Promotion.InvalidMessage));
     }
     else
     {
         if (discount.Expires && discount.ExpirationDate < DateTime.Now)
         {
             return(new Tuple <bool, string>(false, "The " + Promotion.Label + " code has expired"));
         }
         else if (discount.MinValue != null && discount.MinValue > bag.Subtotal)
         {
             return(new Tuple <bool, string>(false, "The " + Promotion.Label + " code requires a min purchase amount of " + Convert.ToDecimal(discount.MinValue).ToString("C")));
         }
         else if (bag.DiscountItems.Where(x => x.Code.ToLower() == discount.Code.ToLower()).Any())
         {
             return(new Tuple <bool, string>(false, "The " + Promotion.Label + "  code has already been added"));
         }
         else
         {
             return(new Tuple <bool, string>(true, ""));
         }
     }
 }
Пример #3
0
        public IExpensesCalculator GetExpensesCalculatorThatHaveNothingDiscount()
        {
            IShoppingBag shoppingBag = GetShoppingBag(1, 450);
            IEnumerable <IDiscountor> discountors = GetDiscountors(24, shoppingBag);

            return(GetExpensesCalculator(shoppingBag, discountors));
        }
Пример #4
0
        public IExpensesCalculator GetExpensesCalculatorThatHaveAllDiscountPromotion()
        {
            IShoppingBag shoppingBag = GetShoppingBag(5, _furnitureCostForDiscountPromotionTest);
            IEnumerable <IDiscountor> discountors = GetDiscountors(60, shoppingBag);

            return(GetExpensesCalculator(shoppingBag, discountors));
        }
Пример #5
0
        private static void ShowPayCost(ICustomer customer, IShoppingBag shoppingBag)
        {
            var expensesCalculator = ShoppingFactory.GetExpensesCalculator(shoppingBag, customer);

            Console.WriteLine($"Product total cost: ${ expensesCalculator.GetTotalCost() }");
            Console.WriteLine($"Product total discount: ${ expensesCalculator.GetTotalDiscount() }");
            Console.WriteLine("Vat percentage is 7%.");
            Console.WriteLine($"Total pay: ${ expensesCalculator.GetTotalPay() }");
        }
Пример #6
0
        public static IExpensesCalculator GetExpensesCalculator(IShoppingBag shoppingBag, ICustomer customer)
        {
            var discountors = new List <IDiscountor>();

            discountors.Add(GetBuyTwoGetOneFreeSnackDiscountor(shoppingBag));
            discountors.Add(GetFurnitureDiscountor(shoppingBag));
            discountors.Add(GetMedicineDiscountor(shoppingBag, customer));
            return(new ExpensesCalculator(shoppingBag, discountors));
        }
Пример #7
0
        public void GetTotalDiscount_VariousTotalSnackProduct_ShouldDiscountByOneOnThreeSnackProduct(int totalSnackProduct, double productCost)
        {
            IShoppingBag shoppingBag           = GetShoppingBag(totalSnackProduct, productCost);
            IDiscountor  snackDiscountor       = new BuyTwoGetOneFreeSnackDiscountor(shoppingBag);
            double       expectedTotalDiscount = productCost * (totalSnackProduct / 3);
            double       actualTotalDiscount   = snackDiscountor.GetTotalDiscount();

            Assert.AreEqual(expectedTotalDiscount, actualTotalDiscount);
        }
Пример #8
0
        public IEnumerable <IDiscountor> GetDiscountors(int customerAge, IShoppingBag shoppingBag)
        {
            var discountors = new List <IDiscountor>();

            discountors.Add(new BuyTwoGetOneFreeSnackDiscountor(shoppingBag));
            discountors.Add(new FurnitureDiscountor(shoppingBag));
            discountors.Add(new MedicineDiscounter(shoppingBag, new Customer("Test", customerAge)));
            return(discountors);
        }
Пример #9
0
        private static void ShowFurnitureDiscount(IShoppingBag shoppingBag)
        {
            IDiscountor furnitureDiscountor    = ShoppingFactory.GetFurnitureDiscountor(shoppingBag);
            double      furnitureTotalDiscount = furnitureDiscountor.GetTotalDiscount();

            if (furnitureTotalDiscount > 0)
            {
                Console.WriteLine($"Discount from furniture promotion: ${ furnitureTotalDiscount }");
            }
        }
Пример #10
0
 public static void ShowReceipt(ICustomer customer, IShoppingBag shoppingBag)
 {
     ShowReceiptTitle(customer, shoppingBag);
     ShowAllAvailableProduct(shoppingBag.GetProductList());
     Console.WriteLine();
     ShowAllAvailableDiscount(customer, shoppingBag);
     Console.WriteLine();
     ShowPayCost(customer, shoppingBag);
     Console.WriteLine("--------------------\n");
 }
Пример #11
0
        private static void ShowMedicineDiscount(IShoppingBag shoppingBag, ICustomer customer)
        {
            IDiscountor medicineDiscountor    = ShoppingFactory.GetMedicineDiscountor(shoppingBag, customer);
            double      medicineTotalDiscount = medicineDiscountor.GetTotalDiscount();

            if (medicineTotalDiscount > 0)
            {
                Console.WriteLine($"Discount from medicine promotion: ${ medicineTotalDiscount }");
            }
        }
Пример #12
0
        private static void ShowSnackDiscount(IShoppingBag shoppingBag)
        {
            IDiscountor snackDiscountor    = ShoppingFactory.GetBuyTwoGetOneFreeSnackDiscountor(shoppingBag);
            double      snackTotalDiscount = snackDiscountor.GetTotalDiscount();

            if (snackTotalDiscount > 0)
            {
                Console.WriteLine($"Discount from snack promotion: ${ snackTotalDiscount }");
            }
        }
Пример #13
0
        public void AddProduct_AddingTwoProduct_TotalProductInBagShouldHaveTwo()
        {
            IShoppingBag shoppingBag = GetShoppingBag();

            shoppingBag.AddProduct(GetProduct());
            shoppingBag.AddProduct(GetProduct());
            var products = shoppingBag.GetProductList();
            int expectedTotalProducts = 2;
            int actualTotalProducts   = products.Count();

            Assert.AreEqual(expectedTotalProducts, actualTotalProducts);
        }
Пример #14
0
        public void RemoveProduct_RemoveProductThatNotInBag_TotalProductShouldNotChange()
        {
            IShoppingBag shoppingBag     = GetShoppingBag();
            IProduct     productInBag    = GetProduct();
            IProduct     productNotInBag = GetProduct();

            shoppingBag.AddProduct(productInBag);
            shoppingBag.RemoveProduct(productNotInBag);
            var products = shoppingBag.GetProductList();
            int expectedTotalProducts = 1;
            int actualTotalProducts   = products.Count();

            Assert.AreEqual(expectedTotalProducts, actualTotalProducts);
        }
Пример #15
0
        public void AllGetTotalMethod_BagHaveNothingProduct_ShouldCalculateCorrectly()
        {
            IShoppingBag shoppingBag = GetShoppingBagHaveNothingProduct();
            IEnumerable <IDiscountor> discountors        = GetDiscountors(20, shoppingBag);
            IExpensesCalculator       expensesCalculator = GetExpensesCalculator(shoppingBag, discountors);
            double expectedTotalCost     = 0;
            double expectedtotalDiscount = 0;
            double expectedtotalPay      = (expectedTotalCost - expectedtotalDiscount) * TAX_RATE;
            double actualTotalCost       = expensesCalculator.GetTotalCost();
            double actualTotalDiscount   = expensesCalculator.GetTotalDiscount();
            double actualTotalPay        = expensesCalculator.GetTotalPay();

            Assert.AreEqual(expectedTotalCost, actualTotalCost);
            Assert.AreEqual(expectedtotalDiscount, actualTotalDiscount);
            Assert.AreEqual(expectedtotalPay, actualTotalPay);
        }
Пример #16
0
        public void RemoveProduct_RemoveTwoProductFromTotalFive_TotalProductInBagShouldHaveThree()
        {
            IShoppingBag shoppingBag = GetShoppingBag();
            IProduct     testProduct = GetProduct();

            for (int i = 0; i < 5; i++)
            {
                shoppingBag.AddProduct(testProduct);
            }

            for (int i = 0; i < 2; i++)
            {
                shoppingBag.RemoveProduct(testProduct);
            }

            var products = shoppingBag.GetProductList();
            int expectedTotalProducts = 3;
            int actualTotalProducts   = products.Count();

            Assert.AreEqual(expectedTotalProducts, actualTotalProducts);
        }
Пример #17
0
 public FurnitureDiscountor(IShoppingBag shoppingBag)
 {
     _shoppingBag = shoppingBag;
 }
Пример #18
0
 public static IDiscountor GetFurnitureDiscountor(IShoppingBag shoppingBag)
 {
     return(new FurnitureDiscountor(shoppingBag));
 }
Пример #19
0
 private static void ShowAllAvailableDiscount(ICustomer customer, IShoppingBag shoppingBag)
 {
     ShowSnackDiscount(shoppingBag);
     ShowFurnitureDiscount(shoppingBag);
     ShowMedicineDiscount(shoppingBag, customer);
 }
Пример #20
0
 private static void ShowReceiptTitle(ICustomer customer, IShoppingBag shoppingBag)
 {
     Console.WriteLine("-----Receipt-----");
     Console.WriteLine($"Customer: { customer.Name }  Age: { customer.Age }");
 }
Пример #21
0
 public static IDiscountor GetMedicineDiscountor(IShoppingBag shoppingBag, ICustomer customer)
 {
     return(new MedicineDiscounter(shoppingBag, customer));
 }
Пример #22
0
 public virtual Tuple <bool, string> Validate(IShoppingBag <string> bag, IDiscount discount)
 {
     return(validate(bag, discount));
 }
Пример #23
0
 public Application(ICustomer customer, IShoppingBag shoppingBag)
 {
     _customer    = customer;
     _shoppingBag = shoppingBag;
 }
Пример #24
0
 public ExpensesCalculator(IShoppingBag shoppingBag,
                           IEnumerable <IDiscountor> discountors)
 {
     _shoppingBag = shoppingBag;
     _discountors = discountors;
 }
Пример #25
0
 public static IDiscountor GetBuyTwoGetOneFreeSnackDiscountor(IShoppingBag shoppingBag)
 {
     return(new BuyTwoGetOneFreeSnackDiscountor(shoppingBag));
 }
Пример #26
0
 public MedicineDiscounter(IShoppingBag shoppingBag, ICustomer customer)
 {
     _shoppingBag = shoppingBag;
     _customer    = customer;
 }
Пример #27
0
 public virtual IShoppingBag <string> Run(IShoppingBag <string> bag, IEnumerable <IDiscount> discounts, string code)
 {
     throw new NotImplementedException();
 }
Пример #28
0
 public BuyTwoGetOneFreeSnackDiscountor(IShoppingBag shoppingBag)
 {
     _shoppingBag = shoppingBag;
 }
Пример #29
0
 public IExpensesCalculator GetExpensesCalculator(IShoppingBag shoppingBag, IEnumerable <IDiscountor> discountors)
 {
     return(new ExpensesCalculator(shoppingBag, discountors));
 }