public GumballMachine(int numberOfGumballs)
 {
     SoldOutState    = new SoldOutState(this);
     NoQuarterState  = new NoQuarterState(this);
     HasQuarterState = new HasQuarterState(this);
     SoldState       = new SoldState(this);
 }
Exemplo n.º 2
0
 public GumBallMachine()
 {
     NoQuarterStateObj  = new NoQuarterState(this);
     HasQuarterStateObj = new HasQuarterState(this);
     SoldStateObj       = new SoldState(this);
     SoldOutStateObj    = new SoldOutState(this);
     state = SoldOutStateObj;
 }
Exemplo n.º 3
0
        public void SetMachineInHasQuarterStateWhenInsertQuarter()
        {
            var machine = new TestGumballMachine();
            var state   = new NoQuarterState(machine);

            state.InsertQuarter();
            Assert.AreEqual((Enums.State)machine.State, Enums.State.HasQuarter);
        }
Exemplo n.º 4
0
 public GumballMachineContext(uint numBalls = 0)
 {
     _count           = numBalls;
     _soldState       = new SoldState(this);
     _soldOutState    = new SoldOutState(this);
     _noQuarterState  = new NoQuarterState(this);
     _hasQuarterState = new HasQuarterState(this);
     _state           = (_count > 0) ? _noQuarterState : (IState)_soldOutState;
 }
Exemplo n.º 5
0
        public void SetMachineInHasQuarterStateWhenInsertQuarter()
        {
            var machine = new TestGumballMachine();
            var state   = new NoQuarterState(machine);

            state.InsertQuarter();
            Assert.AreEqual(machine.GetQuartersController().GetQuartersCount(), (uint)1);
            Assert.AreEqual(machine.State, State.HasQuarter);
        }
Exemplo n.º 6
0
 public GumballMachineContext(uint numBalls = 0)
 {
     _quartersController = new QuartersController(MaxQuartersLimit);
     _count           = numBalls;
     _soldState       = new SoldState(this);
     _soldOutState    = new SoldOutState(this);
     _noQuarterState  = new NoQuarterState(this);
     _hasQuarterState = new HasQuarterState(this);
     _state           = (_count > 0) ? _noQuarterState : (IState)_soldOutState;
 }
Exemplo n.º 7
0
 public GumballMachine(int numberGumballs)
 {
     Count           = numberGumballs;
     SoldOutState    = new SoldOutState(this);
     NoQuarterState  = new NoQuarterState(this);
     HasQuarterState = new HasQuarterState(this);
     SoldState       = new SoldState(this);
     WinnerState     = new WinnerState(this);
     _state          = (Count > 0) ? NoQuarterState : SoldOutState;
 }
Exemplo n.º 8
0
 public GumballMachine(int numberGumballs)
 {
     SoldOutState    = new SoldOutState(this);
     NoQuarterState  = new NoQuarterState(this);
     HasQuarterState = new HasQuarterState(this);
     SoldState       = new SoldState(this);
     WinnerState     = new WinnerState(this);
     Count           = numberGumballs;
     _currentState   = Count > 0 ? NoQuarterState : SoldOutState;
 }
Exemplo n.º 9
0
 public GumballMachine(int ballCount)
 {
     SoldOutState    = new SoldOutState(this);
     NoQuarterState  = new NoQuarterState(this);
     HasQuarterState = new HasQuarterState(this);
     SoldState       = new SoldState(this);
     BallCount       = ballCount;
     if (ballCount > 0)
     {
         State = NoQuarterState;
     }
 }
Exemplo n.º 10
0
        public void ToStringTest()
        {
            var stringWriter              = new StringWriter();
            var gumballMachine            = new GumballMachineContext(2, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";
            var noQuarterState = new NoQuarterState(gumballMachine, stringWriter);

            Assert.AreEqual(noQuarterState.ToString(), BaseConstants.TO_STRING_NO_QUARTER_STATE);
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Exemplo n.º 11
0
 public GumballMachine(int numberOfGumballs)
 {
     Count = numberOfGumballs;
     if (Count > 0)
     {
         State = new NoQuarterState(this);
     }
     else
     {
         State = new SoldOutState(this);
     }
 }
        public GumballMachine(int numberGumBalls)
        {
            SoldState       = new SoldState(this);
            NoQuarterState  = new NoQuarterState(this);
            HasQuarterState = new HasQuarterState(this);

            this.CountGumBall = numberGumBalls;

            if (CountGumBall > 0)
            {
                currentState = NoQuarterState;
            }
        }
Exemplo n.º 13
0
        public GumballMachine(int numberOfGumballs)
        {
            GumballMachineSoldState       = new SoldState(this);
            GumballMachineNoQuarterState  = new NoQuarterState(this);
            GumballMachineHasQuarterState = new HasQuarterState(this);
            GumballMachineSoldOutState    = new SoldOutState(this);
            GumballMachineWinnerState     = new WinnerState(this);

            Count = numberOfGumballs;
            if (Count > 0)
            {
                State = GumballMachineNoQuarterState;
            }
        }
Exemplo n.º 14
0
        public GumballMachine(int numberGumballs)
        {
            SoldOutState    = new SoldOutState(this);
            NoQuarterState  = new NoQuarterState(this);
            HasQuarterState = new HasQuarterState(this);
            SoldState       = new SoldState(this);

            State = SoldOutState;

            this.Count = numberGumballs;
            if (numberGumballs > 0)
            {
                State = NoQuarterState;
            }
        }
Exemplo n.º 15
0
        public void ReFillTest()
        {
            var stringWriter              = new StringWriter();
            var result                    = new StringWriter();
            var gumballMachine            = new GumballMachineContext(2, stringWriter);
            var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" +
                                            $" { 2 } gumball{ ( 2 != 1 ? "s" : "" ) }" +
                                            $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " +
                                            $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })";
            var noQuarterState = new NoQuarterState(gumballMachine, stringWriter);

            noQuarterState.ReFill(10);
            result.WriteLine(MultiGumbalMachineConstants.REFILL_NO_QUARTER_STATE);

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }
Exemplo n.º 16
0
        public void StayMachineInNoQuarterStateWhenRefillIt()
        {
            {
                var machine = new TestGumballMachine();
                machine.SetNoQuarterState();
                machine.BallsCount = 1;
                var state = new NoQuarterState(machine);
                state.Refill(1);
                Assert.AreEqual(machine.GetBallCount(), (uint)2);
                Assert.AreEqual(machine.State, State.NoQuarter);
            }

            {
                var machine = new TestGumballMachine();
                machine.SetNoQuarterState();
                machine.BallsCount = 1;
                var state = new NoQuarterState(machine);
                state.Refill(0);
                Assert.AreEqual(machine.GetBallCount(), (uint)1);
                Assert.AreEqual(machine.State, State.NoQuarter);
            }
        }
Exemplo n.º 17
0
 public NoQuarterStateTest()
 {
     _gumballMachineWithStateMock = new Mock <GumballMachineWithStateContext>();
     _noQuarterState = new NoQuarterState(_gumballMachineWithStateMock.Object);
 }