public void CanDiscountAnOrderByCoupon() { RequestContext c = new RequestContext(); MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c); app.CurrentStore = new Accounts.Store(); app.CurrentStore.Id = 1; // Create a Promotion to Test Promotion p = new Promotion(); p.Mode = PromotionType.Offer; p.IsEnabled = true; p.Name = "Discount By Coupon Test"; p.CustomerDescription = "$20.00 off Test Offer!"; p.StartDateUtc = DateTime.Now.AddDays(-1); p.EndDateUtc = DateTime.Now.AddDays(1); p.StoreId = 1; p.Id = 0; OrderHasCoupon q = new OrderHasCoupon(); q.AddCoupon("COUPON"); p.AddQualification(q); p.AddAction(new OrderTotalAdjustment(AmountTypes.MonetaryAmount, -20m)); app.MarketingServices.Promotions.Create(p); // Create a test Order Order o = new Order(); o.Items.Add(new LineItem() { BasePricePerItem = 59.99m, ProductName = "Sample Product", ProductSku = "ABC123" }); app.CalculateOrderAndSave(o); Assert.AreEqual(59.99m, o.TotalOrderAfterDiscounts, "Order total should be $59.99 before discounts"); o.AddCouponCode("COUPON"); app.CalculateOrderAndSave(o); Assert.AreEqual(39.99m, o.TotalOrderAfterDiscounts, "Order total after discounts should be $39.99"); Assert.AreEqual(-20m, o.TotalOrderDiscounts, "Discount should be -20"); Assert.AreEqual(59.99m, o.TotalOrderBeforeDiscounts, "Order total with coupon but before discount should be $59.99"); }
public void RemoveCouponCodeTest() { Order target = new Order(); RequestContext c = new RequestContext(); c.CurrentStore = new Accounts.Store() { Id = 1 }; OrderRepository repository = OrderRepository.InstantiateForMemory(c); repository.Create(target); target.AddCouponCode("one"); target.AddCouponCode("two"); target.AddCouponCode("three"); repository.Update(target); Assert.IsTrue(target.RemoveCouponCode(target.Coupons[1].Id), "Call to remove failed"); Assert.AreEqual(2, target.Coupons.Count, "Target count should be two!"); Assert.IsTrue(repository.Update(target), "Call to updated failed"); Order actual = repository.FindForCurrentStore(target.bvin); Assert.AreEqual(2, actual.Coupons.Count, "Coupon count didn't match"); for (int i = 0; i < target.Coupons.Count; i++) { Assert.AreEqual(target.Coupons[i].CouponCode, actual.Coupons[i].CouponCode, "Code didn't match for index " + i); } }
public void CanSaveAndRetrieveCouponsInRepository() { Order target = new Order(); RequestContext c = new RequestContext(); c.CurrentStore = new Accounts.Store() { Id = 1 }; OrderRepository repository = OrderRepository.InstantiateForMemory(c); repository.Create(target); target.AddCouponCode("one"); target.AddCouponCode("two"); target.AddCouponCode("three"); repository.Update(target); Order actual = repository.FindForCurrentStore(target.bvin); Assert.AreEqual(target.Coupons.Count, actual.Coupons.Count, "Coupon count didn't match"); for (int i = 0; i < target.Coupons.Count; i++) { Assert.AreEqual(target.Coupons[i].CouponCode, actual.Coupons[i].CouponCode, "Code didn't match for index " + i); } }
public void CanAddCouponAndGetIdNumber() { Order target = new Order(); target.AddCouponCode("one"); target.AddCouponCode("two"); RequestContext c = new RequestContext(); c.CurrentStore = new Accounts.Store() { Id = 1 }; OrderRepository repository = OrderRepository.InstantiateForMemory(c); repository.Create(target); Assert.AreEqual(2, target.Coupons.Count, "Coupon count should be one"); Assert.AreNotEqual(0, target.Coupons[0].Id, "Coupon id should never be zero"); Assert.AreNotEqual(target.Coupons[0].Id, target.Coupons[1].Id, "Coupon ids should be unique"); }
public void CanAddCouponToOrder() { Order target = new Order(); Assert.IsTrue(target.AddCouponCode("coupon"), "Add failed"); Assert.IsTrue(target.CouponCodeExists("coupon"), "Validate Check Failed"); Assert.AreEqual(1, target.Coupons.Count, "Coupon count should be one"); Assert.AreEqual("COUPON", target.Coupons[0].CouponCode, "Code didn't match"); }