public CartServiceTests()
 {
     factory = Substitute.For<ICartFactory>();
     cartRepository = Substitute.For<ICartRepository>();
     productRepository = Substitute.For<IProductRepository>();
     sut = new CartService(cartRepository, productRepository, factory);
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PromotionPipelineFactory"/> class.
 /// </summary>
 /// <param name="cartFactory">The cart factory to use.</param>
 public PromotionPipelineFactory(IList <PromotionRuleOption> promotionRuleOptions,
                                 ICartFactory cartFactory, IEnumerable <Sku> skus)
 {
     this.promotionRuleOptions = promotionRuleOptions ?? throw new ArgumentNullException(nameof(promotionRuleOptions));
     this.cartFactory          = cartFactory ?? throw new ArgumentNullException(nameof(cartFactory));
     this.skus = skus ?? throw new ArgumentNullException(nameof(skus));
 }
 public CartHandler(ICartFactory cartFactory, IOrderGroupFactory orderGroupFactory, IContentLoader contentLoader, ReferenceConverter referenceConverter, ICustomerPriceService customerPriceService, IOrderGroupCalculator orderGroupCalculator)
 {
     _cartFactory          = cartFactory;
     _orderGroupFactory    = orderGroupFactory;
     _contentLoader        = contentLoader;
     _referenceConverter   = referenceConverter;
     _customerPriceService = customerPriceService;
     _orderGroupCalculator = orderGroupCalculator;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CollectionOfSameSkuForRule"/> class.
 /// </summary>
 /// <param name="cartFactory">The <see cref="ICartFactory"/> to use to generate a cart.</param>
 /// <param name="sku">The <see cref="PromoEng.Engine.Sku"/>.</param>
 /// <param name="quantity">The quantity of the same amount of items of the <see cref="PromoEng.Engine.Sku"/>.</param>
 /// <param name="totalPrice">The overall price to assign to the batch.</param>
 public CollectionOfSameSkuForRule(ICartFactory cartFactory, Sku sku, int quantity, decimal totalPrice)
 {
     this.cartFactory = cartFactory ?? throw new ArgumentNullException(nameof(cartFactory));
     this.Sku         = sku ?? throw new ArgumentNullException(nameof(sku));
     this.Quantity    = quantity != 0
         ? Math.Abs(quantity)
         : throw new ArgumentException(nameof(quantity), "Quantity cannot be zero");
     this.TotalPrice = Math.Abs(totalPrice);
 }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PairOfDifferentSkusForRule"/> class.
        /// </summary>
        /// <param name="cartFactory">The <see cref="ICartFactory"/> to use to generate a cart.</param>
        /// <param name="sku1">The first <see cref="Sku"/>.</param>
        /// <param name="sku2">The second <see cref="Sku"/>.</param>
        /// <param name="totalPrice">The total price to assign to the couple.</param>
        public PairOfDifferentSkusForRule(ICartFactory cartFactory, Sku sku1, Sku sku2, decimal totalPrice)
        {
            this.cartFactory = cartFactory ?? throw new ArgumentNullException(nameof(cartFactory));
            this.Sku1        = sku1 ?? throw new ArgumentNullException(nameof(sku1));
            this.Sku2        = sku2 ?? throw new ArgumentNullException(nameof(sku2));
            this.TotalPrice  = Math.Abs(totalPrice);

            if (this.Sku1.CompareTo(this.Sku2) == 0)
            {
                throw new ArgumentException("Cannot use the same SKU in the rule", nameof(sku2));
            }
        }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CartController"/> class.
 /// </summary>
 /// <param name="logger">The logger to use.</param>
 /// <param name="dataSource">The database to use.</param>
 /// <param name="cartFactory">The cart factory to use.</param>
 /// <param name="priceList">The price list holding the list of <see cref="Sku"/> and their prices.</param>
 /// <param name="promotionPipeline">The pipeline to use.</param>
 public CartController(ILogger <CartController> logger,
                       IInMemoryCollection <CartsCollection.CartsCollectionEntry> dataSource,
                       ICartFactory cartFactory,
                       IDictionary <Sku, decimal> priceList,
                       IPromotionPipeline promotionPipeline)
 {
     this.logger            = logger;
     this.dataSource        = dataSource ?? throw new ArgumentNullException(nameof(dataSource));
     this.cartFactory       = cartFactory ?? throw new ArgumentNullException(nameof(cartFactory));
     this.priceList         = priceList ?? throw new ArgumentNullException(nameof(priceList));
     this.promotionPipeline = promotionPipeline ?? throw new ArgumentNullException(nameof(promotionPipeline));
 }
Beispiel #7
0
        public void setup()
        {
            _cartFactory = new CartFactory(_mockPromotionRepository.Object, _mockProductRepository.Object);
            //Setup Products
            _mockProductRepository.Setup(repo => repo.GetProduct("111"))
            .Returns(new ProductInfo {
                ProductId = "111", ProductName = "APPLE", UnitPriceInCents = 75
            });
            _mockProductRepository.Setup(repo => repo.GetProduct("222"))
            .Returns(new ProductInfo {
                ProductId = "222", ProductName = "ORANGE", UnitPriceInCents = 50
            });

            //Setup Promotions
            _mockPromotionRepository.Setup(repo => repo.GetPromotions("111", TEST_ORDER_DATE))
            .Returns(new List <PromotionInfo> {
                GetAppleSalePricePromo()
            }.AsReadOnly);
        }
Beispiel #8
0
        public ShoppingCart(ICartRepository cartRepository, ICartFactory cartFactory, IOrderRepository orderRepository)
        {
            if (cartRepository == null)
            {
                throw new ArgumentNullException();
            }

            if (cartFactory == null)
            {
                throw new ArgumentNullException();
            }

            if (orderRepository == null)
            {
                throw new ArgumentNullException();
            }

            this.cartRepository  = cartRepository;
            this.cartFactory     = cartFactory;
            this.orderRepository = orderRepository;
        }
 public CartService(ICartRepository cartRepository, IProductRepository productRepository, ICartFactory factory)
 {
     this.factory = factory;
     this.cartRepository = cartRepository;
     this.productRepository = productRepository;
 }
Beispiel #10
0
 public TestPromotionPipelineFactory(IList <PromotionRuleOption> promotionRuleOptions,
                                     ICartFactory cartFactory, IEnumerable <Sku> skus)
     : base(promotionRuleOptions, cartFactory, skus)
 {
     this.PromotionRules = new List <IPromotionRule>();
 }
Beispiel #11
0
 public ApiCartService(IRepository <Cart> cart, ICartFactory cartFactory)
 {
     _cart        = cart ?? throw new ArgumentNullException(nameof(cart));
     _cartFactory = cartFactory ?? throw new ArgumentNullException(nameof(cartFactory));
 }
Beispiel #12
0
 public CheckoutController(ICartFactory cartFactory)
 {
     _cartFactory = cartFactory;
 }
Beispiel #13
0
 public InvariantPromotionRule(ICartFactory cartFactory)
 {
     this.cartFactory = cartFactory;
 }
Beispiel #14
0
 public TestContext()
 {
     this.PriceList   = new Dictionary <Sku, decimal>();
     this.CartFactory = new TestCartFactory(this.PriceList);
 }