Esempio n. 1
0
        public void SendMessage_Should_Send_Correct_Instructions_For_Tea_With_Sugar_Order()
        {
            // GIVEN
            IDrinkMakerProtocol drinkMakerProtocol = new DrinkMakerProtocol();
            ICashRegister       cashRegister       = new CashRegister();

            CoffeeMachineLogic coffeeMachineLogic = new CoffeeMachineLogic(drinkMakerProtocol, cashRegister);

            IHotDrink drink = new Tea();

            drink.AddSugar();
            IDrinkOrder drinkOrder = new DrinkOrder(drink);

            var price = drinkOrder.GetPrice();

            coffeeMachineLogic.InsertMoney(price);

            // WHEN
            string command = coffeeMachineLogic.SendCommand(drinkOrder);

            // THEN
            Check.That(command).IsEqualTo("T:1:1");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Bar bar = new Bar();

            Console.WriteLine();
            Console.WriteLine("Start ordering");
            //TODO: Catch Exceptions
            Beverage tea_12 = bar.Order(12, new Tea(200));
            Tea      t      = tea_12 as Tea;

            t.AddSugar();
            t.AddMilk(200);
            Console.WriteLine(t.ToString());
            t.Drink(399);
            Console.WriteLine(t.ToString());

            try
            {
                Beverage coffee_15 = bar.Order(15, new Coffee(100));
                Coffee   c         = coffee_15 as Coffee;
                c.AddSugar();
                c.AddSugar();
            }
            catch (AlreadySugarInsideException e)
            {
                Console.WriteLine("Catched Exception: " + e.GetType());
                Console.WriteLine("Coffee already has sugar inside");
            }

            Beverage cola_13 = bar.Order(13, new Cola(250));

            try
            {
                Beverage beer_14 = bar.Order(14, new Beer(1000));
            }
            catch (NoAlcoholicBeverageException e)
            {
                Console.WriteLine("Catched Exception: " + e.GetType());
                Console.WriteLine(e);
            }

            try
            {
                Beverage wine_64 = bar.Order(64, new Wine(125));
                wine_64.Drink(126);
            }
            catch (NotEnoughException e)
            {
                Console.WriteLine("Catched Exception: " + e.GetType());
                Console.WriteLine(e);
            }

            try
            {
                Beverage whiksey_20 = bar.Order(20, new Whiskey(50));
                whiksey_20.Drink(50);
                Console.WriteLine(whiksey_20.ToString());
                Beverage whiskey_cola = bar.Order(17, new Whiskey(300));
            }
            catch (NoAlcoholicBeverageException e)
            {
                Console.WriteLine(e.GetType());
                Console.WriteLine(e);
            }
        }