Example #1
0
        static void Main(string[] args) {
            if (args.Length == 0) {
                Console.WriteLine("No input files provided.");
                return;
            }

            string filename = args[0];
            if (!File.Exists(filename)) {
                Console.WriteLine("File does not exist: " + filename);
                return;
            }

            Checkout checkout = new Checkout();
            checkout.PerformCheckout(filename);
        }
Example #2
0
        static void Main(string[] args)
        {
            var checkout = new Checkout();
            var run      = true;

            Console.WriteLine("SKU  Price  Offer");
            Console.WriteLine(" A      50  3 for 130");
            Console.WriteLine(" B      30  2 for 45");
            Console.WriteLine(" C      20");
            Console.WriteLine(" D      15");
            Console.WriteLine();
            Console.WriteLine("Press T for total.");

            do
            {
                Console.WriteLine();

                var action      = Console.ReadLine();
                var actionUpper = action?.ToUpper();

                switch (actionUpper)
                {
                case "A":
                case "B":
                case "C":
                case "D":
                    checkout.Scan(actionUpper);
                    break;

                case "T":
                    Console.WriteLine($"Your total is: £{checkout.GetTotalPrice()}");
                    break;

                case "X":
                    run = false;
                    break;
                }
            } while (run);
        }
Example #3
0
        public void Test(string items, double expectedPrice)
        {
            // Arrange
            var checkout = new Checkout(new List <IPriceDeltaRule>
            {
                new PriceDeltaRule('A', 50),
                new PriceDeltaRule('B', 30),
                new PriceDeltaRule('C', 20),
                new PriceDeltaRule('D', 15),
                new MultiPriceDeltaRule('A', 3, -20),
                new MultiPriceDeltaRule('B', 2, -15)
            });

            foreach (var item in items)
            {
                checkout.Scan(item);
            }

            // Act
            var totalPrice = checkout.CalculateTotalPrice();

            // Assert
            Assert.That(totalPrice, Is.EqualTo(expectedPrice));
        }
        public void InvalidSKUTest()
        {
            var co = new Checkout(_pricingRules);

            Assert.Throws <Exception>(() => co.Scan("Invalid_SKU"));
        }