public void Get_Regular_Total_With_Duplicate_Products() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); //Act decimal total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(4.25m, total); }
public void Get_Discounted_Total_With_Expired_On_Sale_Promotion() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.ApplyPromotion(new OnSalePromotion("Apple", DateTime.Now.AddMonths(-12), DateTime.Now.AddMonths(-6), "Apple is on-sale", 0.5m)); //Act decimal total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(4.25m, total); }
public void Get_Discounted_Total_With_Mixed_Promotion() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.ApplyPromotion(new OnSalePromotion("Apple", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Apple is on-sale", 0.7m)); sale.ApplyPromotion(new GroupSalePromotion("Apple", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Apple group sale", 2, 1m)); //Act decimal total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(1.75m, total); }
public void Get_Discount_Total_With_Group_Sale_Promotion() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddPromotion(new GroupSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has group-sale", 3, 2m)); //Act decimal total = sale.GetPromotionTotal(); //Assert Assert.AreEqual(4.00m, total); }
public void Get_Discounted_Total_With_Group_Sale_Promotion() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.ApplyPromotion(new GroupSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has group-sale", 3, 2m)); //Act decimal total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(2.00m, total); // Reassign sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); //Act total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(4.00m, total); // Reassign sale.ClearPromotions(); sale.ApplyPromotion(new GroupSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has group-sale", 10, 2m)); //Act total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(5.00m, total); }
public static void Run(string fileLocation) { string line; StreamReader runFile = new StreamReader(@fileLocation); Product p = null, pAux = null; Sale s = null; string productName; int productAmount, selledAmount, saleCode; while ((line = runFile.ReadLine()) != null) { string[] sellParams = line.Split(';'); saleCode = int.Parse(sellParams[0]); productAmount = int.Parse(sellParams[1]); s = new Sale(saleCode); for (int i = 0; i < productAmount; i++) { line = runFile.ReadLine(); string[] saleParams = line.Split(';'); productName = saleParams[0]; selledAmount = int.Parse(saleParams[1]); pAux = Stock.GetProduct(productName); for (int j = 0; j < selledAmount; j++) { s.AddProduct(pAux); Stock.AddSaleToProduct(s.GetHashCode(), pAux); } } Stock.AddSale(s); } }
/// <summary> /// Add basket products in sale class /// </summary> /// <param name="id"></param> public void AddProduct(string productId) { var product = productRepository.GetById(productId); if (product == null) { throw new ProductException("There's a product(s) which is not registered in the catalog."); } sale.AddProduct(product); }
public void Get_Discount_Total_With_On_Sale_Promotion() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddPromotion(new OnSalePromotion("Apple", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Apple is on-sale", 0.5m)); //Act decimal total1 = sale.GetPromotionTotal(); //Assert Assert.AreEqual(4.00m, total1); //More Arrage sale.AddPromotion(new OnSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana is on-sale", 0.5m)); //Act decimal total2 = sale.GetPromotionTotal(); //Assert Assert.AreEqual(3.00m, total2); }
private void button2_Click(object sender, EventArgs e) { Product toAdd = Stock.GetProduct(name.Text); for (int i = (int)amount.Value; i > 0; i--) { currentSale.AddProduct(toAdd); } UpdateConsole(); Reset(); }
public void Get_Regular_Total() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); //Act decimal total = sale.GetRegularTotal(); //Assert Assert.AreEqual(3.25m, total); }
public void Add_Product() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Apple", Price = 0.75m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); sale.AddProduct(new Product() { Id = "Orange", Price = 1.50m }); //Act var salesLineItem = sale.GetSaleLineItems(); //Assert Assert.AreEqual(1, salesLineItem.Single(x => x.Product.Id == "Apple").Quantity); Assert.AreEqual(2, salesLineItem.Single(x => x.Product.Id == "Banana").Quantity); Assert.AreEqual(3, salesLineItem.Single(x => x.Product.Id == "Orange").Quantity); }
public void Get_Discounted_Total_With_Additional_Sale_Promotion() { //Arrange Sale sale = new Sale(); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); sale.ApplyPromotion(new AdditionalSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has buy one get one free sale", 1, 0f)); //Act decimal total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(3.00m, total); //Rearrange sale.AddProduct(new Product() { Id = "Banana", Price = 1.00m }); //Act total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(3.00m, total); //Rearrange sale.ClearPromotions(); sale.ApplyPromotion(new AdditionalSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has buy one get 50% off free sale", 1, 0.5f)); //Act total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(4.50m, total); //Rearrange sale.ClearPromotions(); sale.ApplyPromotion(new AdditionalSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has buy two get one 50% off sale", 2, 0.5f)); //Act total = sale.CreateReceipt().GetTotalPayment(); //Assert Assert.AreEqual(5.00m, total); }