public void SpecialOfferLoaderReturnsAllOffers(ISpecialOffer offer)
        {
            var specialOfferLoader = new SpecialOfferLoader();
            var specialOffers      = specialOfferLoader.LoadCurrentOffers();

            Assert.Contains(offer, specialOffers.ToList());
        }
Example #2
0
        static void Main(string[] args)
        {
            //load the Products
            var products = new ProductLoader().LoadProducts();

            //take the arguments and put them through the validator to make sure they are all valid items
            IInputValidator validator = new InputValidator(products);

            if (!validator.ValidateInput(args))
            {
                //TODO: could return which of the inputs were invalid
                Console.WriteLine("Invalid input received.");
                return;
            }
            //pass the newly validated products into the checkout to determine the subtotal
            var checkout = new Checkout(validator.GetValidatedProducts());

            Console.WriteLine($"Subtotal: {string.Format("{0:C}", checkout.DetermineSubtotal())}");
            //load the special offers
            var specialOffers = new SpecialOfferLoader(DateTime.Today.AddDays(3)).LoadCurrentOffers();

            checkout.ProcessSpecialOffers(specialOffers);
            if (checkout.GetSpecialOffers().Any())
            {
                foreach (Product offer in checkout.GetSpecialOffers())
                {
                    Console.WriteLine($"{ offer.ProductName}: {string.Format("{0:C}", offer.Price)}");
                }
            }
            else
            {
                Console.WriteLine("(No offers available)");
            }
            Console.WriteLine($"Total: {string.Format("{0:C}", checkout.DetermineTotal())}");
        }
        public void CheckNumberOfOffersLoadedLastYear()
        {
            var lastYear = new DateTime(2017, 3, 25);
            var loader   = new SpecialOfferLoader(lastYear);
            var products = loader.LoadCurrentOffers();

            Assert.AreEqual <int>(0, products.Count);
        }
        public void CheckNumberOfOffersLoadedFor28thApril2018()
        {
            var thisYear = new DateTime(2018, 3, 25);
            var loader   = new SpecialOfferLoader(thisYear);
            var products = loader.LoadCurrentOffers();

            Assert.AreEqual <int>(2, products.Count);
        }
Example #5
0
        static void Main(string[] args)
        {
            var productLoader  = new ProductLoader();
            var inputValidator = new InputValidator(productLoader);

            Console.WriteLine("Please enter the products to calculate as CSV (i.e. 'Milk,Bread,Butter':");
            var input = Console.ReadLine().Split(',');

            if (!inputValidator.ValidateInput(input))
            {
                //TODO: could return which of the inputs were invalid
                Console.WriteLine("Invalid input received.");
                Console.ReadKey();
                return;
            }
            //load the specialOffers and pass to the checkout to determine savings
            var specialOfferLoader = new SpecialOfferLoader();
            var checkout           = new Checkout(inputValidator.GetValidatedProducts());

            checkout.ProcessSpecialOffers(specialOfferLoader.LoadCurrentOffers());

            Console.Write($"These products come to £{checkout.DetermineTotal().ToString("0.00")}");
            Console.ReadKey();
        }