public void ProcessOrderWithTwoOrderedProductAndOnePromoProductAndCheckCountInContext() { var context = new OrderCalculationContext(new Order() { Id = 1, OrderToProducts = new List <OrderToProduct>() { new OrderToProduct() { IdProduct = 1, QTY = 2, }, new OrderToProduct() { IdProduct = 2, QTY = 5.5m }, new OrderToProduct() { IdProduct = 5, QTY = 5, IdUsedBuyGetPromotion = 10 }, } }); _action.ExecuteAction(context, _executingContext); Assert.Equal(2, context.OrderToProducts.Count); Assert.Contains(context.OrderToProducts, p => p.IdProduct == 1); Assert.Contains(context.OrderToProducts, p => p.IdProduct == 2); }
public PricePromotionsActionTest() { _executingContext = Mock.Of <IWorkflowProcessorContext>(); _action = new PricePromotionsAction(); _context = new OrderCalculationContext(new Order() { Id = 1, }); _context.OrderToProducts = new List <OrderToProduct>() { new OrderToProduct() { IdProduct = 1, QTY = 1, Price = _firstOrderToProductPrice, }, new OrderToProduct() { IdProduct = 2, QTY = 1.5m, Price = _secondOrderToProductPrice, }, new OrderToProduct() { IdProduct = 11, Price = _promoOrderToProductPrice, IdUsedBuyGetPromotion = 1 } }; }
public void ProcessOrderWithTwoOrderedProductAndCheckCorrectPriceAndAmount() { var context = new OrderCalculationContext(new Order() { Id = 1, OrderToProducts = new List <OrderToProduct>() { new OrderToProduct() { IdProduct = 1, QTY = 2, }, new OrderToProduct() { IdProduct = 2, QTY = 5.5m }, } }); _action.ExecuteAction(context, _executingContext); Assert.Equal(2, context.OrderToProducts.Count); Assert.Equal(10.5m, context.OrderToProducts.First(p => p.IdProduct == 1).Price); Assert.Equal(10.5m * 2, context.OrderToProducts.First(p => p.IdProduct == 1).Amount); Assert.Equal(15m, context.OrderToProducts.First(p => p.IdProduct == 2).Price); Assert.Equal(15m * 5.5m, context.OrderToProducts.First(p => p.IdProduct == 2).Amount); }
private OrderCalculationContext GetContextForBuyTwoGetTwoOneRule(int?limit = null) { var context = new OrderCalculationContext(new Order() { Id = 1 }); context.OrderToProducts = new List <OrderToProduct>() { new OrderToProduct() { IdProduct = 1, QTY = 4, }, new OrderToProduct() { IdProduct = 2, QTY = 2, } }; context.ActivePromotions = new List <BasePromotion>() { new BuyXGetYPromotion() { Id = 1, ApplyLimit = limit, BuyItems = new List <BuyPromotionItem>() { new BuyPromotionItem() { IdProduct = 1, QTY = 2, }, new BuyPromotionItem() { IdProduct = 2, QTY = 1, } }, GetItems = new List <GetPromotionItem>() { new GetPromotionItem() { IdProduct = 11, QTY = 2, PercentDiscount = 100, }, new GetPromotionItem() { IdProduct = 12, QTY = 1, PercentDiscount = 50, } } } }; return(context); }
private Order GetRecalculatedOrder(Order order) { var context = new OrderCalculationContext(order); context = _calculationProcessor.CalculateOrder(context); return(context.GetResultOrder()); }
public void ProcessOrderWittZerosProductsAndCheckCountInContext() { var context = new OrderCalculationContext(new Order() { Id = 1, }); _action.ExecuteAction(context, _executingContext); Assert.Equal(0, context.OrderToProducts.Count); }
public void SetupZeroActivePromotionsAndCheckCount() { var context = new OrderCalculationContext(new Order() { Id = 1, }); var executingContext = GetExecutingContext(new List <BasePromotion>()); _action.ExecuteAction(context, executingContext); Assert.Equal(0, context.ActivePromotions.Count); }
public void SetupMultipleActivePromotionsAndCheckThatOnlyAvaliableOnThisTimeExists() { var context = new OrderCalculationContext(new Order() { Id = 1, }); var executingContext = GetExecutingContext(new List <BasePromotion>() { new PricePromotion() { Id = 1, StartDate = DateTime.Now.AddMonths(-1), EndDate = DateTime.Now.AddMonths(1), }, new PricePromotion() { Id = 2, StartDate = DateTime.Now.AddMonths(-1), EndDate = null, }, new PricePromotion() { Id = 3, StartDate = null, EndDate = null, }, new PricePromotion() { Id = 4, StartDate = DateTime.Now.AddMonths(1), EndDate = null, }, new PricePromotion() { Id = 5, StartDate = DateTime.Now.AddMonths(-2), EndDate = DateTime.Now.AddMonths(-1), }, }); _action.ExecuteAction(context, executingContext); Assert.Equal(3, context.ActivePromotions.Count); Assert.Contains(context.ActivePromotions, p => p.Id == 1); Assert.Contains(context.ActivePromotions, p => p.Id == 2); Assert.Contains(context.ActivePromotions, p => p.Id == 3); }
public void TryToApplyBuyGetRuleWithNotExistInStoreProductFromGetSectionAndCheckThatItWasNotAdded() { var context = new OrderCalculationContext(new Order() { Id = 1 }); context.OrderToProducts = new List <OrderToProduct>() { new OrderToProduct() { IdProduct = 1, QTY = 4, } }; context.ActivePromotions = new List <BasePromotion>() { new BuyXGetYPromotion() { Id = 1, BuyItems = new List <BuyPromotionItem>() { new BuyPromotionItem() { IdProduct = 1, QTY = 2, }, }, GetItems = new List <GetPromotionItem>() { new GetPromotionItem() { IdProduct = 21, QTY = 2, PercentDiscount = 100, }, } } }; context.ActivePromotions = new List <BasePromotion>(); _action.ExecuteAction(context, _executingContext); Assert.Equal(1, context.OrderToProducts.Count); Assert.True(context.OrderToProducts.FirstOrDefault(p => p.IdProduct == 21) == null); }
private OrderCalculationContext GetContextWithMultipleRulesForTheSameProduct() { var context = new OrderCalculationContext(new Order() { Id = 1 }); context.OrderToProducts = new List <OrderToProduct>() { new OrderToProduct() { IdProduct = 1, QTY = 4, } }; context.ActivePromotions = new List <BasePromotion>() { new BuyXGetYPromotion() { Id = 1, BuyItems = new List <BuyPromotionItem>() { new BuyPromotionItem() { IdProduct = 1, QTY = 2, }, }, GetItems = new List <GetPromotionItem>() { new GetPromotionItem() { IdProduct = 11, QTY = 2, PercentDiscount = 100, }, } }, new BuyXGetYPromotion() { Id = 2, BuyItems = new List <BuyPromotionItem>() { new BuyPromotionItem() { IdProduct = 1, QTY = 1, } }, GetItems = new List <GetPromotionItem>() { new GetPromotionItem() { IdProduct = 12, QTY = 1.1m, PercentDiscount = 50, } } } }; return(context); }