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();
        }
        static void Main(string[] args)
        {
            var gumballMachine = new GumballMachine(5);

            var i = 10;

            while (true)
            {
                while (i != 0)
                {
                    Console.WriteLine(gumballMachine);

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

                    Console.WriteLine(gumballMachine);

                    i--;
                }

                Thread.Sleep(5000);
                gumballMachine.Refill(10);
            }

            Console.ReadKey();
        }
        public void Refill_WithBalls_SouldRefillGumballMachine()
        {
            var gm = new GumballMachine(5);

            gm.Refill(2);
            Assert.AreEqual(GetGumballMachineString(7, "waiting for quarter"), gm.ToString());
        }
        public void Refill_InSoldOutState_ShouldRefill()
        {
            var gm = new GumballMachine(0);

            Assert.AreEqual(GetGumballMachineString(0, "sold out"), gm.ToString());

            sb.Remove(0, sb.Length);
            gm.Refill(2);
            Assert.AreEqual("Gumballs refilled. Gumballs count: 2\r\n", sw.ToString());
        }
        public static void Run()
        {
            GumballMachine gumballMachine = new GumballMachine(5);

            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);
        }
        public void CanRefillGumballMachineWithAddingMoreThan0GumballsInSoldOutStateAndMoveToNoQuarterState()
        {
            var  strState = "waiting for quarter";
            uint gumballs = 1;
            var  testStr  = GetGumballMachineTestParsedString(gumballs, strState);
            var  gM       = new GumballMachine();

            gM.Refill(gumballs);
            Assert.AreEqual(gM.GetBallCount(), gumballs);
            Assert.AreEqual(gM.ToString(), testStr);
        }
        public void CanRefillGumballMachineWithAdding0GumballsInSoldOutState()
        {
            var  strState = "sold out";
            uint gumballs = 0;
            var  testStr  = GetGumballMachineTestParsedString(gumballs, strState);
            var  gM       = new GumballMachine(gumballs);

            gM.Refill(0);
            Assert.AreEqual(gM.GetBallCount(), gumballs);
            Assert.AreEqual(gM.ToString(), testStr);
        }
        public void Refill_InNoQuarterState_ShouldRefill()
        {
            var gm = new GumballMachine(2);

            Assert.AreEqual(GetGumballMachineString(2, "waiting for quarter"), gm.ToString());

            sb.Remove(0, sb.Length);
            gm.Refill(2);

            Assert.AreEqual("Gumballs refilled. Gumballs count: 4\r\n", sw.ToString());
        }
        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());
        }
        public void CanRefillMachineInHasQuarterState()
        {
            var  strState = "waiting for turn of crank";
            uint gumballs = 2;
            var  testStr  = GetGumballMachineTestParsedString(gumballs, strState);
            var  gM       = new GumballMachine(1);

            gM.InsertQuarter();
            gM.Refill(1);
            Assert.AreEqual(gM.GetBallCount(), gumballs);
            Assert.AreEqual(gM.ToString(), testStr);
        }
        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.
        }