Example #1
0
        static void Main(string[] args)
        {
            var skuIds = args.Any() ? args[0] : "";

            try
            {
                // Initialise the checkout with a list of SKUs and offers...
                Setup();

                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;

                ConsoleKeyInfo cki;

                Console.BackgroundColor = ConsoleColor.DarkGreen;
                WriteLineCentered("GoCompare Checkout");

                Console.BackgroundColor = ConsoleColor.Black;
                WriteLineCentered("Press A-D to add items to the basket.");
                WriteLineCentered("Press <Enter> to complete the checkout.");
                Console.WriteLine();

                do
                {
                    cki = Console.ReadKey(true);

                    var skuId = Char.ToUpper(cki.KeyChar);

                    switch (skuId)
                    {
                    case 'A':
                    case 'B':
                    case 'C':
                    case 'D':
                        try
                        {
                            _checkout.AddItemToBasket(skuId);
                            Console.Write("{0} ", skuId);
                        }
                        catch (CheckoutException ex)
                        {
                            Console.Error.WriteLine("Checkout Error: {0}", ex.Message);
                        }

                        break;
                    }
                } while (cki.Key != ConsoleKey.Enter);

                Console.WriteLine();
                Console.WriteLine();

                // Show the basket details...
                ShowBasketDetails(_checkout);

                Console.WriteLine();
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Unexpected Error: {0}", ex.Message);
            }
        }