Example #1
0
        public void SetMachineInNoQuarterStateWhenRefillItWithMoreThan0Balls()
        {
            var machine = new TestGumballMachine();
            var state   = new SoldOutState(machine);

            state.Refill(1);
            Assert.AreEqual(machine.GetBallCount(), (uint)1);
            Assert.AreEqual(machine.State, State.NoQuarter);
        }
Example #2
0
        public void StayMachineInSoldOutStateWhenRefillItWith0Balls()
        {
            var machine = new TestGumballMachine();
            var state   = new SoldOutState(machine);

            machine.SetSoldOutState();
            state.Refill(0);
            Assert.AreEqual(machine.GetBallCount(), (uint)0);
            Assert.AreEqual(machine.State, State.SoldOut);
        }
Example #3
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);
            }
        }
Example #4
0
        public void CantRefillMachine()
        {
            {
                var machine = new TestGumballMachine();
                machine.SetSoldState();
                machine.BallsCount = 1;
                var state = new SoldState(machine);
                state.Refill(1);
                Assert.AreEqual(machine.GetBallCount(), (uint)1);
                Assert.AreEqual(machine.State, State.Sold);
            }

            {
                var machine = new TestGumballMachine();
                machine.SetSoldState();
                machine.BallsCount = 1;
                var state = new SoldState(machine);
                state.Refill(0);
                Assert.AreEqual(machine.GetBallCount(), (uint)1);
                Assert.AreEqual(machine.State, State.Sold);
            }
        }