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
         }
     };
 }
Exemple #2
0
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var buyGetPromotions = context.ActivePromotions.Where(p => p is BuyXGetYPromotion)
                                   .Select(p => (BuyXGetYPromotion)p);
            var notPromoProducts      = context.OrderToProducts.ToList();
            var appliedPromotionInfos = new List <Tuple <BuyXGetYPromotion, int> >();

            foreach (var promotion in buyGetPromotions)
            {
                var useCount = GetPossiableNumberOfUse(promotion, notPromoProducts);
                if (promotion.ApplyLimit.HasValue)
                {
                    useCount = Math.Min(useCount, promotion.ApplyLimit.Value);
                }

                if (useCount > 0)
                {
                    appliedPromotionInfos.Add(new Tuple <BuyXGetYPromotion, int>(promotion, useCount));
                }
            }

            if (appliedPromotionInfos.Count > 0)
            {
                var productIds     = appliedPromotionInfos.SelectMany(p => p.Item1.GetItems).Select(p => p.IdProduct).ToList();
                var productService = processorContext.Resolve <IProductService>();
                var products       = productService.GetProducts(productIds, true);
                SetPricesForPromoProducts(context, products, appliedPromotionInfos);
            }
        }
        public SetupOrderedProductsInfoActionTest()
        {
            var executingContextSetup = new Mock <IWorkflowProcessorContext>();
            var productServiceSetup   = new Mock <IProductService>();

            productServiceSetup.Setup(p => p.GetProducts(new List <int>()
            {
                1, 2
            }, false)).Returns(new List <Product>()
            {
                new Product()
                {
                    Id        = 1,
                    Price     = 10.5m,
                    PriceType = PriceType.PerEach
                },
                new Product()
                {
                    Id        = 2,
                    Price     = 15m,
                    PriceType = PriceType.PerLb
                },
            });
            productServiceSetup.Setup(p => p.GetProducts(new List <int>()
            {
            }, false)).Returns(new List <Product>()
            {
            });

            executingContextSetup.Setup(p => p.Resolve <IProductService>()).
            Returns(productServiceSetup.Object);
            _executingContext = executingContextSetup.Object;
            _action           = new SetupOrderedProductsInfoAction();
        }
Exemple #4
0
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var promotionService = processorContext.Resolve <IPromotionService>();

            context.ActivePromotions = promotionService.GetPromotions().Where(p =>
                                                                              (!p.StartDate.HasValue || p.StartDate.Value <= DateTime.Now) &&
                                                                              (!p.EndDate.HasValue || p.EndDate.Value >= DateTime.Now)).ToList();
        }
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var pricePromotions = context.ActivePromotions.Where(p => p is PricePromotion)
                                  .Select(p => (PricePromotion)p).ToList();

            foreach (var orderToProduct in context.OrderToProducts.Where(p => !p.IdUsedBuyGetPromotion.HasValue))
            {
                var biggestPromotion = pricePromotions.Where(p => p.AssignedProductIds.Contains(orderToProduct.IdProduct))
                                       .OrderByDescending(p => p.PriceDiscount).FirstOrDefault();

                if (biggestPromotion != null)
                {
                    orderToProduct.Price = Math.Max(orderToProduct.Price - biggestPromotion.PriceDiscount, 0);
                }
            }
        }
        public BuyXGetYPromotionsActionTest()
        {
            var executingContextSetup = new Mock <IWorkflowProcessorContext>();
            var productServiceSetup   = new Mock <IProductService>();

            productServiceSetup.Setup(p => p.GetProducts(new List <int>()
            {
                11, 12
            }, true)).Returns(new List <Product>()
            {
                _firstGetPromoProduct,
                _secondGetPromoProduct
            });

            executingContextSetup.Setup(p => p.Resolve <IProductService>()).
            Returns(productServiceSetup.Object);
            _executingContext = executingContextSetup.Object;
            _action           = new BuyXGetYPromotionsAction();
        }
        public void ExecuteAction(OrderCalculationContext context, IWorkflowProcessorContext processorContext)
        {
            var productsInOrderWithoutPromotions = context.SourceOrder.OrderToProducts.
                                                   Where(p => !p.IdUsedBuyGetPromotion.HasValue).ToList();

            var productService = processorContext.Resolve <IProductService>();
            var products       = productService.GetProducts(productsInOrderWithoutPromotions.Select(p => p.IdProduct).ToList());

            foreach (var item in productsInOrderWithoutPromotions)
            {
                var product = products.FirstOrDefault(p => p.Id == item.IdProduct);
                if (product != null)
                {
                    var orderToProduct = new OrderToProduct();
                    orderToProduct.IdProduct = item.IdProduct;
                    orderToProduct.QTY       = item.QTY;
                    orderToProduct.Price     = product.Price;
                    context.OrderToProducts.Add(orderToProduct);
                }
            }
        }
 public void ExecuteAction(FakeWorkflowDataContent context, IWorkflowProcessorContext processorContext)
 {
     context.StringData += "3";
 }