public void TestTeaWithHook()

        {
            if (Convert.ToBoolean(ConfigurationSettings.AppSettings["WantCodiments?"].ToString()))

            {
                teaWithHookYesResult.Append("Boiling water\n");

                teaWithHookYesResult.Append("Steeping the tea\n");

                teaWithHookYesResult.Append("Pouring into cup\n");

                teaWithHookYesResult.Append("Adding lemon\n");

                Assert.AreEqual(teaWithHookYesResult.ToString(),

                                teaWithHook.PrepareRecipe());
            }

            else

            {
                teaWithHookNoResult.Append("Boiling water\n");

                teaWithHookNoResult.Append("Steeping the tea\n");

                teaWithHookNoResult.Append("Pouring into cup\n");

                Assert.AreEqual(teaWithHookNoResult.ToString(),

                                teaWithHook.PrepareRecipe());
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("USING INHERITANCE");
            Console.WriteLine("---------------------------------------------------");
            TeaWithHook    teaHook    = new TeaWithHook();
            CoffeeWithHook coffeeHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking tea...");
            teaHook.PrepareRecipe();
            Console.WriteLine("\nMaking coffee...");
            coffeeHook.PrepareRecipe();

            Duck[] ducks =
            {
                new Duck("Daffy",   8),
                new Duck("Dewey",   2),
                new Duck("Howard",  7),
                new Duck("Louie",   2),
                new Duck("Donald", 10),
                new Duck("Huey", 2)
            };

            Console.WriteLine("\n\n.NET EXAMPLE (ORDERING ARRAYS)");
            Console.WriteLine("---------------------------------------------------");
            Console.WriteLine("\nBefore sorting:");
            Display(ducks);
            Array.Sort(ducks);
            Console.WriteLine("\nAfter sorting:");
            Display(ducks);
            Console.ReadKey();
        }
Example #3
0
        public void TemplateMethod_CanUseHooks()
        {
            CaffeineBeverageWithHook coffee = new CoffeWithHook();
            CaffeineBeverageWithHook tea    = new TeaWithHook();

            System.Console.WriteLine("Making coffee....");
            coffee.PrepareRecipe();
            System.Console.WriteLine("Making tea.....");
            tea.PrepareRecipe();
        }
 public void TestTeaWithHook()
 {
     if (teaWithHook.CustomerWantsCondiments())
     {
         teaWithHookYesResult.Append("Boiling water\n");
         teaWithHookYesResult.Append("Steeping the tea\n");
         teaWithHookYesResult.Append("Pouring into cup\n");
         teaWithHookYesResult.Append("Adding lemon\n");
         Assert.AreEqual(teaWithHookYesResult.ToString(),
                         teaWithHook.PrepareRecipe());
     }
     else
     {
         teaWithHookNoResult.Append("Boiling water\n");
         teaWithHookNoResult.Append("Steeping the tea\n");
         teaWithHookNoResult.Append("Pouring into cup\n");
         Assert.AreEqual(teaWithHookNoResult.ToString(),
                         teaWithHook.PrepareRecipe());
     }
 }
Example #5
0
        public static void Run()
        {
            TeaWithHook    teaHook    = new TeaWithHook();
            CoffeeWithHook coffeeHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking tea...");
            teaHook.PrepareRecipe();

            Console.WriteLine("\nMaking coffee...");
            coffeeHook.PrepareRecipe();
        }
        static void Main(string[] args)
        {
            var teaWithHook    = new TeaWithHook();
            var coffeeWithHook = new CoffeeWithHook();

            Console.WriteLine("\nMaking tea...");
            teaWithHook.PrepareRecipe();

            Console.WriteLine("\nMaking coffee...");
            coffeeWithHook.PrepareRecipe();
        }
Example #7
0
        static void MakeCoffeeWithHook()
        {
            var teaWithHook = new TeaWithHook();

            Console.WriteLine("Making tea...");
            teaWithHook.PrepareRecipe();

            Console.WriteLine("***************");

            var coffeeWithHook = new CoffeeWithHook();

            Console.WriteLine("Making coffee...");
            coffeeWithHook.PrepareRecipe();
        }
        public void TemplateMethodTest()
        {
            Tea    tea    = new Tea();
            Coffee coffee = new Coffee();

            Console.WriteLine("${Environment.NewLine}Making tea...");
            tea.PrepareRecipe();

            Console.WriteLine($"{Environment.NewLine}Making coffee...");
            coffee.PrepareRecipe();

            TeaWithHook    teaHook    = new TeaWithHook();
            CoffeeWithHook coffeeHook = new CoffeeWithHook();

            Console.WriteLine($"{Environment.NewLine}Making tea...");
            teaHook.PrepareRecipe();

            Console.WriteLine($"{Environment.NewLine}Making coffee...");
            coffeeHook.PrepareRecipe();
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n--- Tea ---");
            var tea = new Tea();

            tea.PrepareRecipe();

            Console.WriteLine("\n--- Coffee ---");
            var coffee = new Coffee();

            coffee.PrepareRecipe();

            Console.WriteLine("\n--- Tea (with hook)---");
            var teaWithHook = new TeaWithHook();

            teaWithHook.PrepareRecipe();

            Console.WriteLine("\n--- Coffee (with hook) ---");
            var coffeeWithHook = new CoffeeWithHook();

            coffeeWithHook.PrepareRecipe();
        }
Example #10
0
        static void Main(string[] args)
        {
            #region Strategy
            // Duck mallard = new MallardDuck();
            // mallard.PerformQuack();
            // mallard.PerformFly();

            // Duck model = new ModelDuck();
            // model.PerformFly();
            // model.SetFlyBehavior(new FlyRocketPowered());
            // model.PerformFly();
            #endregion

            #region Observer
            // var weatherData = new WeatherData();

            // var currentDisplay = new CurrentConditions(weatherData);

            // weatherData.SetMeasurements(80, 65, 30.4);
            // weatherData.SetMeasurements(82, 70, 29.2);
            // weatherData.SetMeasurements(78, 90, 29.2);
            #endregion

            #region Decorator
            // var beverage = new Espresso();
            // System.Console.WriteLine($"{beverage.GetDescription()} ${beverage.Cost()}\n");

            // Beverage beverage2 = new DarkRoast();
            // beverage2 = new Mocha(beverage2);
            // beverage2 = new Mocha(beverage2);
            // beverage2 = new Whip(beverage2);
            // System.Console.WriteLine($"{beverage2.GetDescription()} ${beverage2.Cost()}\n");

            // Beverage beverage3 = new HouseBlend();
            // beverage3 = new Soy(beverage3);
            // beverage3 = new Mocha(beverage3);
            // beverage3 = new Whip(beverage3);
            // System.Console.WriteLine($"{beverage3.GetDescription()} ${beverage3.Cost()}\n");
            #endregion

            #region Factory
            // PizzaStore nyPizzaStore = new NYPizzaStore();
            // Pizza pizza = nyPizzaStore.OrderPizza("cheese");

            // System.Console.WriteLine($"Ethan ordered a {pizza.Name}");
            #endregion

            #region Singleton
            // var singleInstance = Singleton.GetInstance();

            // var testNewInstance = Singleton.GetInstance();
            #endregion

            #region Command
            // var remote = new SimpleRemoteControl();

            // var light = new Light();

            // ICommand lightOn = new LightOnCommand(light);

            // remote.SetCommand(lightOn);
            // remote.ButtonWasPressed();

            // var remoteControl = new RemoteControl();

            // var livingRoomLight = new Light("Living Room");
            // var kitchenLight = new Light("Kitchen");

            // var stereo = new Stereo("Living Room");

            // ICommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
            // ICommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            // ICommand kitchenLightOn = new LightOnCommand(kitchenLight);
            // ICommand kitchenLightOff = new LightOffCommand(kitchenLight);

            // remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);
            // remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff);

            // System.Console.WriteLine(remoteControl);

            // remoteControl.OnButtonWasPushed(0);
            // remoteControl.OffButtonWasPushed(0);

            // remoteControl.OnButtonWasPushed(1);
            // remoteControl.OffButtonWasPushed(1);
            #endregion

            #region Adapter and Facade
            // MallardDuck duck = new MallardDuck();

            // WildTurkey turkey = new WildTurkey();
            // Duck turkeyAdapter = new TurkeyAdapter(turkey);

            // System.Console.WriteLine("The Turkey says...");
            // turkey.Gobble();
            // turkey.Fly();
            #endregion

            #region TemplateMethod
            // CaffeineBeverage tea = new Tea();
            // tea.PrepareRecipe();

            // CaffeineBeverage coffe = new Coffe();
            // coffe.PrepareRecipe();

            CaffeineBeverageWithHook coffeeWithHook = new CoffeWithHook();
            coffeeWithHook.PrepareRecipe();

            CaffeineBeverageWithHook teaWithHook = new TeaWithHook();
            teaWithHook.PrepareRecipe();
            #endregion
        }