public void TestGumballMachine()
        {
            DesignPatterns.State.GumballMachine.GumballMachine gumballMachine = new DesignPatterns.State.GumballMachine.GumballMachine(5);
            StringBuilder gumballMachineOutput = new StringBuilder();

            gumballMachineOutput.Append(gumballMachine.MachineStateHeader() + "\n");

            gumballMachineOutput.Append(gumballMachine.InsertQuarter());
            gumballMachineOutput.Append(gumballMachine.TurnCrank() + "\n");

            gumballMachineOutput.Append(gumballMachine.MachineStateHeader() + "\n");

            gumballMachineOutput.Append(gumballMachine.InsertQuarter());
            gumballMachineOutput.Append(gumballMachine.TurnCrank());
            gumballMachineOutput.Append(gumballMachine.InsertQuarter());
            gumballMachineOutput.Append(gumballMachine.TurnCrank() + "\n");

            gumballMachineOutput.Append(gumballMachine.MachineStateHeader() + "\n");

            gumballMachineOutput.Append(gumballMachine.Refill(5) + "\n");

            gumballMachineOutput.Append(gumballMachine.MachineStateHeader() + "\n");



            //Because of the System.Random object, there is no way to know
            //the outcome of the turn of the crank. Therefore, I am writing
            //to the console. Use the Console.Out tab of NUnit
            Console.WriteLine(gumballMachineOutput.ToString());
        }
示例#2
0
 public WinnerState(GumballMachine gumballMachine)
 {
     this.gumballMachine = gumballMachine;
     soldOutState        = new SoldOutState(gumballMachine);
     noQuarterState      = new NoQuarterState(gumballMachine);
 }
示例#3
0
 public NoQuarterState(GumballMachine gumballMachine)
 {
     this.gumballMachine = gumballMachine;
     hasQuarterState     = new HasQuarterState(gumballMachine);
 }