Example #1
0
        [TestCase("AAABBBBBAA", 305)]  // 3 offers and >1 individual
        public void CheckoutTotalPriceCalculationWithMixedOffersTest(string skuIds, decimal expectedTotalPrice)
        {
            var start = new DateTime(2017, 2, 7);
            var end   = new DateTime(2017, 2, 9);

            var availableSkus = new SkuDictionary {
                { 'A', new Sku("Apple", 50m) },
                { 'B', new Sku("Banana", 30m) }
            };

            var offers = new OfferDictionary {
                { 'A', new QtyBasedOffer(3, 130m) },
                { 'B', new TimeSensitiveOffer(15m, start, end) }
            };

            using (ShimsContext.Create())
            {
                System.Fakes.ShimDateTime.NowGet = () => { return(new DateTime(2017, 2, 8)); };

                var checkout = _factory.Create(availableSkus, offers);

                checkout.AddRangeOfItemsToBasket(skuIds);

                Assert.That(expectedTotalPrice, Is.EqualTo(checkout.TotalPrice()));
            }
        }
Example #2
0
        /// <summary>
        /// Secondary constructor for supplying a non-default list of available SKUs
        /// </summary>
        /// <param name="skus"></param>
        public Checkout(SkuDictionary skus, OfferDictionary offers)
        {
            _skus   = skus;
            _offers = offers;

            _basket = new BasketDictionary();
        }
Example #3
0
        public void Setup()
        {
            _availableSkus = new SkuDictionary {
                { 'A', new Sku("Apple", 50m) },
                { 'B', new Sku("Banana", 30m) },
                { 'C', new Sku("Canteloupe", 20m) },
                { 'D', new Sku("Damson", 15m) }
            };

            _offers = new OfferDictionary {
                { 'A', new QtyBasedOffer(3, 130m) },
                { 'B', new QtyBasedOffer(2, 45m) }
            };
        }
Example #4
0
        /// <summary>
        /// Initialise the checkout with a list of SKUs and offers...
        /// </summary>
        private static void Setup()
        {
            _availableSkus = new SkuDictionary {
                { 'A', new Sku("Apple", 50m) },
                { 'B', new Sku("Banana", 30m) },
                { 'C', new Sku("Canteloupe", 20m) },
                { 'D', new Sku("Damson", 15m) }
            };

            _offers = new OfferDictionary {
                { 'A', new QtyBasedOffer(3, 130m) },
                { 'B', new QtyBasedOffer(2, 45m) },
                { 'C', new TimeSensitiveOffer(10m, DateTime.Now, DateTime.Now.AddDays(1)) }
            };

            var factory = new CheckoutFactory();

            _checkout = factory.Create(_availableSkus, _offers);
        }
Example #5
0
 /// <summary>
 /// Create a Checkout instance with a custom list of available SKUs and offers.
 /// </summary>
 /// <param name="skus">A dictionary of available SKU IDs and their associated details</param>
 /// <param name="offers">A dictionary of offers</param>
 /// <returns></returns>
 public Checkout Create(SkuDictionary skus, OfferDictionary offers)
 {
     return(new Checkout(skus, offers));
 }