// apply discount public Order ApplyDiscount(DiscountCupon cupon) { DiscountCupon = cupon; TotalWithDiscount = Total - (Total * (cupon.Percentage / 100)); AddEvent(new AppliedDiscountEvent(Id, Customer.Id, Number, Status, Total, TotalWithDiscount, DiscountCupon.Cod, DiscountCupon.Percentage)); return(this); }
public DiscountCuponFakeReaderRepository() { _cupons = new List <DiscountCupon>(); var cupon1 = new DiscountCupon("XPTO1", 5, Period.Monthly); var cupon2 = new DiscountCupon("XPTO2", 10, Period.Monthly); var cupon3 = new DiscountCupon("XPTO3", 15, Period.Monthly); var cupon4 = new DiscountCupon("XPTO4", 20, Period.Monthly); var cupon5 = new DiscountCupon("XPTO5", 25, Period.Monthly); var cupon6 = new DiscountCupon("XPTO6", 30, Period.Monthly); var cupon7 = new DiscountCupon("XPTO8", 5, Period.Create(new DateTime(2008, 12, 25), new DateTime(2008, 12, 26))); _cupons.Add(cupon1); _cupons.Add(cupon2); _cupons.Add(cupon3); _cupons.Add(cupon4); _cupons.Add(cupon5); _cupons.Add(cupon6); _cupons.Add(cupon7); }
public void ShouldApplyTenPercentageOfDisountValidOrder() { // add products in order _products.ToList().ForEach(x => { _order.AddItem(x, 5); }); // create a cupon var cupom = new DiscountCupon("DESCONTOTOTAL", 10, Period.Fortnightly); // create an order _order.Place(); _order.ApplyDiscount(cupom); Assert.AreEqual(_order.TotalWithDiscount, _order.Total - (_order.Total * 10 / 100)); Assert.AreEqual(EOrderStatus.Created, _order.Status); Assert.AreEqual(true, _order.IsValid()); }
public void ShouldCreateInvalidDiscountCupon() { var discountCupon = new DiscountCupon("XPTO", 10, Period.Create(new DateTime(2008, 12, 25), new DateTime(2008, 12, 26))); Assert.AreEqual(false, discountCupon.IsValid()); }
public void ShouldCreateValidDiscountCupon() { var discountCupon = new DiscountCupon("XPTO", 10, Period.Fortnightly); Assert.AreEqual(true, discountCupon.IsValid()); }