void Demo1(GumballMachine gumballMachine)
        {
            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine(gumballMachine);
        }
        public static void Run(string[] args)
        {
            int count = 0;

            if (args.Length < 2)
            {
                Console.WriteLine("GumballMachine <name> <inventory>");
                Environment.Exit(1);
            }

            count = int.Parse(args[1]);
            GumballMachine gumballMachine = new GumballMachine(args[0], count);

            GumballMonitor monitor = new GumballMonitor(gumballMachine);

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.Refill(3);
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.Refill(3);

            monitor.Report();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello State!");

            GumballMachine gumballMachine = new GumballMachine(5);

            Console.WriteLine(gumballMachine);
            Console.WriteLine("");

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();


            //Console.WriteLine(gumballMachine);
            //Console.WriteLine("");

            //gumballMachine.InsertQuarter();
            //gumballMachine.TurnCrank();
            //gumballMachine.InsertQuarter();
            //gumballMachine.TurnCrank();


            Console.WriteLine(gumballMachine);
            Console.WriteLine("");

            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();


            Console.WriteLine(gumballMachine);
            Console.WriteLine("");

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();


            Console.WriteLine(gumballMachine);
            Console.WriteLine("");

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine(gumballMachine);
        }
Esempio n. 4
0
        public void EjectQuarter_InNoQuarterState_ShouldNotChangeGMState()
        {
            var gm = new GumballMachine(5);

            gm.EjectQuarter();

            Assert.AreEqual(GetGumballMachineString(5, "waiting for quarter"), gm.ToString());
        }
Esempio n. 5
0
        public void EjectWhenSoldOut()
        {
            GumballMachine gumballMachine = CreateGumballMachine(NO_GUMBALLS);

            gumballMachine.EjectQuarter();

            this.AssertMachineMessage(MachineMessages.EjectWhenSoldOut);
        }
Esempio n. 6
0
        public void EjectWhenNoQuarter()
        {
            GumballMachine gumballMachine = CreateGumballMachine(1);

            gumballMachine.EjectQuarter();

            this.AssertMachineMessage(MachineMessages.EjectWhenNoQuarter);
        }
Esempio n. 7
0
        public void EjectQuarter()
        {
            GumballMachine gumballMachine = CreateGumballMachine(1);

            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();

            this.AssertMachineMessage(MachineMessages.EjectSuccessfully);
        }
        public void State_GumballMachineTraversal()
        {
            GumballMachine machine = new GumballMachine(1);

            machine.InsertQuarter();
            machine.EjectQuarter();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.InsertQuarter();
        }
Esempio n. 9
0
        public static void Run()
        {
            GumballMachine gumballMachine = new GumballMachine(5);

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

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

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

            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();

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

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();

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

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine();
            Console.WriteLine(gumballMachine);
        }
        public void State_GumballMachineRefill()
        {
            GumballMachine machine = new GumballMachine(1);

            machine.InsertQuarter();
            machine.EjectQuarter();
            machine.InsertQuarter();
            machine.TurnCrank();
            machine.Refill(10);
            machine.InsertQuarter();
            Assert.AreEqual(10, machine.GetCount());
        }
Esempio n. 11
0
        public void EjectQuarter_InSoldOutState_ShouldReturnAllQuarters()
        {
            var gm = new GumballMachine(1);

            gm.InsertQuarter();
            gm.InsertQuarter();
            gm.TurnCrank();
            sb.Remove(0, sb.Length);
            gm.EjectQuarter();

            Assert.AreEqual("Quarter returned\r\n", sw.ToString());
            Assert.AreEqual(GetGumballMachineString(0, "sold out"), gm.ToString());
        }
Esempio n. 12
0
        private static void TestState()
        {
            GumballMachine gumballMachine = new GumballMachine(1);

            Console.WriteLine("--Chamando todos os métodos que não mudam o estado do estado atual: {0}", gumballMachine.GetState());
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.ReleaseGum();
            Console.WriteLine("--Inserindo a moeda para alterar o estado.");
            gumballMachine.InsertQuarter();
            Console.WriteLine("--{0} gomas.", gumballMachine.Count);
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("--Chamando todos os métodos que não mudam o estado do estado atual: {0}", gumballMachine.GetState());
            gumballMachine.InsertQuarter();
            gumballMachine.ReleaseGum();
            Console.WriteLine("--Ejetando a moeda para alterar o estado.");
            gumballMachine.EjectQuarter();
            Console.WriteLine("--{0} gomas.", gumballMachine.Count);
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("--Chamando todos os métodos que não mudam o estado do estado atual: {0}", gumballMachine.GetState());
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.ReleaseGum();
            Console.WriteLine("--Inserindo novamente a moeda para alterar o estado.");
            gumballMachine.InsertQuarter();
            Console.WriteLine("--{0} gomas.", gumballMachine.Count);
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("--Chamando todos os métodos que não mudam o estado do estado atual: {0}", gumballMachine.GetState());
            gumballMachine.InsertQuarter();
            gumballMachine.ReleaseGum();
            Console.WriteLine("--Virando a engrenagem.");
            gumballMachine.TurnCrank();
            Console.WriteLine("--{0} gomas.", gumballMachine.Count);
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("--Chamando todos os métodos que não mudam o estado do estado atual: {0}", gumballMachine.GetState());
            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();
            Console.WriteLine("--Dispensando a goma.");
            gumballMachine.ReleaseGum();
            Console.WriteLine("--{0} gomas.", gumballMachine.Count);
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("--Chamando todos os métodos que não mudam o estado do estado atual: {0}", gumballMachine.GetState());
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.ReleaseGum();
            gumballMachine.EjectQuarter();
            Console.WriteLine("--Repondo as gomas.");
            gumballMachine.Fill();
            Console.WriteLine("--{0} gomas.", gumballMachine.Count);
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("--Estado atual: {0}", gumballMachine.GetState());
        }
Esempio n. 13
0
        private void State_Click(object sender, RoutedEventArgs e)
        {
            var gumballMachine = new GumballMachine("2004", 5);

            Console.WriteLine(gumballMachine);
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine();
            Console.WriteLine(gumballMachine);
            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine();
            Console.WriteLine(gumballMachine);
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();

            Console.WriteLine();
            Console.WriteLine(gumballMachine);
            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();

            Console.WriteLine();
            Console.WriteLine(gumballMachine);
            gumballMachine.Fill(1);
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
        }
Esempio n. 14
0
        public void EjectQuarter_InHasQuarterState_ShouldReturnAllQuarters_And_ChangeGMStateToNoQuarterState()
        {
            var gm = new GumballMachine(5);

            gm.InsertQuarter();
            gm.InsertQuarter();

            Assert.AreEqual("You inserted a quarter. Quarters count: 1\r\nYou inserted a quarter. Quarters count: 2\r\n", sw.ToString());

            sb.Remove(0, sb.Length);
            gm.EjectQuarter();

            Assert.AreEqual(GetGumballMachineString(5, "waiting for quarter"), gm.ToString());
        }
Esempio n. 15
0
        public void ShouldCorrectTransferState()
        {
            var gumballMachine = new GumballMachine(10);

            Assert.Equal(gumballMachine.GetState().GetType(), typeof(NoQuarterState));

            gumballMachine.InsertQuarter();

            Assert.Equal(gumballMachine.GetState().GetType(), typeof(HasQuarterState));

            gumballMachine.EjectQuarter();

            Assert.Equal(gumballMachine.GetState().GetType(), typeof(NoQuarterState));
        }
Esempio n. 16
0
        public static void Main(string[] args)
        {
            Console.WriteLine("\n\n\r===========Working with Strategy Pattern=======");

            RedHeadDuck redHeadDuck = new RedHeadDuck();

            redHeadDuck.PerformFly();
            redHeadDuck.PerformQuack();
            redHeadDuck.Swim();
            redHeadDuck.Display();
            Console.WriteLine("\n\rSetting the Behaviour for Ducks that exibit different Behaviours");

            RubberDuck rubberDuck = new RubberDuck();

            rubberDuck.PerformFly();
            rubberDuck.SetFlyBehaviour(new FlyWithRockets());
            rubberDuck.PerformFly();
            rubberDuck.PerformQuack();


            Console.WriteLine("\n\n\r===========Working with Observer Pattern=======");

            WeatherData WeatherData = new WeatherData();

            ForecastDisplay forcastDisplay = new ForecastDisplay(WeatherData);

            WeatherData.WeatherMeasurements(15, 20, 25);

            Console.WriteLine("\n\n\r===========Working with Classic Singleton=======");
            ClassicSingleton classicSingleton = ClassicSingleton.GetInstance();

            classicSingleton.Description();

            Console.WriteLine("\n\n\r===========Working with Static Singleton=======");
            StaticSingleton staticSingleton = StaticSingleton.GetInstance();

            staticSingleton.Description();

            Console.WriteLine("\n\n\r===========Working with Singleton using syncronization=======");
            SingletonUsingSyncronization syncronizedSingleton = SingletonUsingSyncronization.GetInstance();

            syncronizedSingleton.Description();


            Console.WriteLine("\n\n\r===========Working with Factory Design Pattern=======");
            SimplePizzaFactory factory = new SimplePizzaFactory();

            PizzaStore store = new PizzaStore(factory);
            Pizza      pizza = store.OrderPizza("Cheese");

            Console.WriteLine(pizza.ToString());

            Console.WriteLine("\nState Machine Design Pattern");

            GumballMachine machine = new GumballMachine(5);

            Console.WriteLine(machine);

            machine.InsertQuarter();
            machine.EjectQuarter();
            machine.TurnCrank();
            Console.WriteLine(machine);

            Console.WriteLine("\n Working with Iterators");
            DinnerMenu dinnerMenu = new DinnerMenu();

            DesignPatterns.Iterator.Iterator iterator = dinnerMenu.CreateIterator();

            while (iterator.HasNext())
            {
                var current = iterator.Next();
                Console.WriteLine(current);
            }

            Console.WriteLine("\n============================");
            PanCakeHouseMenu panMenu = new PanCakeHouseMenu();

            DesignPatterns.Iterator.Iterator panIterator = panMenu.CreateIterator();

            while (panIterator.HasNext())
            {
                var current = panIterator.Next();
                Console.WriteLine(current);
            }
        }
        public static void Run(string[] args)
        {
            int count = 0;

            if (args.Length < 2)
            {
                Console.WriteLine("GumballMachine <name> <inventory>");
                Environment.Exit(1);
            }

            count = int.Parse(args[1]);

            //Step 1: Create an instance of the WCF proxy.

            GumballMachine gumballMachine = new GumballMachine(args[0], count);

            // Step 2: Call the service operations.
            GumballMonitor monitor = new GumballMonitor(gumballMachine);

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.EjectQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.Refill(3);
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.EjectQuarter();
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            gumballMachine.InsertQuarter();
            gumballMachine.TurnCrank();
            Console.WriteLine();

            Console.WriteLine(gumballMachine);

            gumballMachine.Refill(3);

            monitor.Report();

            //Step 3: Closing the client gracefully closes the connection and cleans up resources.
        }