public void ApplyBuyXGetYFree_NoMatchProductsBuyQuantity_DoNothing() { // Arrange var price = 100; var privilegedPrice = price / 2; var buyXGetYFree = new SPRBuyXGetYFree() { Id = Guid.NewGuid(), IsActive = true, ProductId = Guid.NewGuid(), Buy = 3, Charge = 1 }; var products = new List <Product>() { new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = buyXGetYFree.ProductId, Price = price } }; var totalBefore = JobAdsCheckoutService.CalculateTotal(products); // Act buyXGetYFree.Apply(products); // Assert Assert.AreEqual(totalBefore, JobAdsCheckoutService.CalculateTotal(products)); Assert.AreEqual(0, products.Count(X => X.SpecialPricingRuleID != null)); Assert.AreEqual(0, products.Count(X => X.privilegedPrice != 0)); }
public void ApplyQuantityDiscount_NoMatchProductsMinimumQuantity_DoNothing() { // Arrange var price = 100; var privilegedPrice = price / 2; var quantityDiscount = new SPRQuantityDiscount() { Id = Guid.NewGuid(), IsActive = true, ProductId = Guid.NewGuid(), NewPrice = privilegedPrice, MinimumQuantity = 3 }; var products = new List <Product>() { new Product() { Id = quantityDiscount.ProductId, Price = price }, new Product() { Id = quantityDiscount.ProductId, Price = price } }; var totalBefore = JobAdsCheckoutService.CalculateTotal(products); // Act quantityDiscount.Apply(products); // Assert Assert.AreEqual(totalBefore, JobAdsCheckoutService.CalculateTotal(products)); Assert.AreEqual(0, products.Count(X => X.SpecialPricingRuleID != null)); Assert.AreEqual(0, products.Count(X => X.privilegedPrice != 0)); }
//http://localhost:8080/api/checkout?CutomerId=1&Products=2,10 //http://localhost:8080/api/checkout?CutomerId=9ef6ac0b-9f36-4db4-a498-0070a00b7af8&Products=018a5e88-0f30-4409-b78c-2d8a824d70b7,018a5e88-0f30-4409-b78c-2d8a824d70b7,018a5e88-0f30-4409-b78c-2d8a824d70b7,c5b2084c-9bd7-400f-bf9a-9be14453c7c0 //Console.WriteLine("{0} \n{1} \n{2}", "Customer: Unilever", // "SKUs Scanned: 'classic', 'classic', 'classic', 'premium'", // "Total expected: $934.97"); public IHttpActionResult Checkout([ModelBinder(typeof(CommaDelimitedArrayModelBinder))] CheckoutData ResourceQuery) { try { //using (var context = new AppDbContext()) { var total = new JobAdsCheckoutService(new PricingRulesService(new JsonPricingRulesRepository()), new ProductService(new JsonProductRepository())) .Checkout(ResourceQuery.cutomerId, ResourceQuery.productsId); return(Ok(total)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void ApplyBuyXGetYFree_Matched_ApplyDiscountOverAllMatchedProducts() { // Arrange var price = 100; var buyXGetYFree = new SPRBuyXGetYFree() { Id = Guid.NewGuid(), IsActive = true, ProductId = Guid.NewGuid(), Buy = 3, Charge = 1 }; var products = new List <Product>() { new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = Guid.NewGuid(), Price = 0 }, new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = Guid.NewGuid(), Price = 0 }, new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = Guid.NewGuid(), Price = 0 }, new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = Guid.NewGuid(), Price = 0 }, new Product() { Id = Guid.NewGuid(), Price = 0 }, new Product() { Id = buyXGetYFree.ProductId, Price = price }, new Product() { Id = buyXGetYFree.ProductId, Price = price }, }; // 7P1 = 7 * 100 = 700 var totalBefore = JobAdsCheckoutService.CalculateTotal(products); var matchedProductsCount = products.Count(X => X.Id == buyXGetYFree.ProductId); // Act buyXGetYFree.Apply(products); // 7P1 = 3P1(100) + 3P1(100) + 100 = 300 // Assert Assert.AreEqual(totalBefore, JobAdsCheckoutService.CalculateTotal(products) * matchedProductsCount / buyXGetYFree.Buy); Assert.AreEqual(matchedProductsCount - (matchedProductsCount % buyXGetYFree.Buy), products.Count(X => X.SpecialPricingRuleID != null)); Assert.AreEqual((matchedProductsCount - (matchedProductsCount % buyXGetYFree.Buy)) / buyXGetYFree.Buy, products.Count(X => X.privilegedPrice != 0)); }