public IExpensesCalculator GetExpensesCalculatorThatHaveDiscountFromMedicine() { IShoppingBag shoppingBag = GetShoppingBag(1, 450); IEnumerable <IDiscountor> discountors = GetDiscountors(60, shoppingBag); return(GetExpensesCalculator(shoppingBag, discountors)); }
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, "")); } } }
public IExpensesCalculator GetExpensesCalculatorThatHaveNothingDiscount() { IShoppingBag shoppingBag = GetShoppingBag(1, 450); IEnumerable <IDiscountor> discountors = GetDiscountors(24, shoppingBag); return(GetExpensesCalculator(shoppingBag, discountors)); }
public IExpensesCalculator GetExpensesCalculatorThatHaveAllDiscountPromotion() { IShoppingBag shoppingBag = GetShoppingBag(5, _furnitureCostForDiscountPromotionTest); IEnumerable <IDiscountor> discountors = GetDiscountors(60, shoppingBag); return(GetExpensesCalculator(shoppingBag, discountors)); }
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() }"); }
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)); }
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); }
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); }
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 }"); } }
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"); }
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 }"); } }
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 }"); } }
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); }
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); }
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); }
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); }
public FurnitureDiscountor(IShoppingBag shoppingBag) { _shoppingBag = shoppingBag; }
public static IDiscountor GetFurnitureDiscountor(IShoppingBag shoppingBag) { return(new FurnitureDiscountor(shoppingBag)); }
private static void ShowAllAvailableDiscount(ICustomer customer, IShoppingBag shoppingBag) { ShowSnackDiscount(shoppingBag); ShowFurnitureDiscount(shoppingBag); ShowMedicineDiscount(shoppingBag, customer); }
private static void ShowReceiptTitle(ICustomer customer, IShoppingBag shoppingBag) { Console.WriteLine("-----Receipt-----"); Console.WriteLine($"Customer: { customer.Name } Age: { customer.Age }"); }
public static IDiscountor GetMedicineDiscountor(IShoppingBag shoppingBag, ICustomer customer) { return(new MedicineDiscounter(shoppingBag, customer)); }
public virtual Tuple <bool, string> Validate(IShoppingBag <string> bag, IDiscount discount) { return(validate(bag, discount)); }
public Application(ICustomer customer, IShoppingBag shoppingBag) { _customer = customer; _shoppingBag = shoppingBag; }
public ExpensesCalculator(IShoppingBag shoppingBag, IEnumerable <IDiscountor> discountors) { _shoppingBag = shoppingBag; _discountors = discountors; }
public static IDiscountor GetBuyTwoGetOneFreeSnackDiscountor(IShoppingBag shoppingBag) { return(new BuyTwoGetOneFreeSnackDiscountor(shoppingBag)); }
public MedicineDiscounter(IShoppingBag shoppingBag, ICustomer customer) { _shoppingBag = shoppingBag; _customer = customer; }
public virtual IShoppingBag <string> Run(IShoppingBag <string> bag, IEnumerable <IDiscount> discounts, string code) { throw new NotImplementedException(); }
public BuyTwoGetOneFreeSnackDiscountor(IShoppingBag shoppingBag) { _shoppingBag = shoppingBag; }
public IExpensesCalculator GetExpensesCalculator(IShoppingBag shoppingBag, IEnumerable <IDiscountor> discountors) { return(new ExpensesCalculator(shoppingBag, discountors)); }