Beispiel #1
0
        public void SetMachineInNoQuarterStateWhenEjectQuarters()
        {
            var machine = new TestGumballMachine();

            machine.GetQuartersController().InsertQuarter();
            var state = new HasQuarterState(machine);

            state.EjectQuarters();
            Assert.IsFalse(machine.GetQuartersController().HasQuarters());
            Assert.AreEqual(machine.State, State.NoQuarter);
        }
Beispiel #2
0
        public void StayMachineInHasQuarterStateWhenInsertQuarter()
        {
            var machine = new TestGumballMachine();

            machine.SetHasQuarterState();
            machine.GetQuartersController().InsertQuarter();
            var state = new HasQuarterState(machine);

            state.InsertQuarter();
            Assert.IsTrue(machine.GetQuartersController().HasQuarters());
            Assert.AreEqual(machine.GetQuartersController().GetQuartersCount(), (uint)2);
            Assert.AreEqual(machine.State, State.HasQuarter);
        }
Beispiel #3
0
        public void SetGumballMachineInSoldOutStateIfDispenseWith1BallAnd1QuarterInMachine()
        {
            var  machine     = new TestGumballMachine();
            uint ballsAmount = 1;

            machine.GetQuartersController().InsertQuarter();
            machine.BallsCount = ballsAmount;
            var state = new SoldState(machine);

            state.Dispense();
            Assert.AreEqual((uint)0, machine.BallsCount);
            Assert.IsFalse(machine.GetQuartersController().HasQuarters());
            Assert.AreEqual(machine.State, State.SoldOut);
        }
Beispiel #4
0
        public void SetGumballMachineInHasQuarterStateIfDispenseWithMoreThan1BallsAndMoreThan1QuarterInMachine()
        {
            var machine = new TestGumballMachine();

            machine.GetQuartersController().InsertQuarter();
            machine.GetQuartersController().InsertQuarter();
            uint ballsAmount = 2;

            machine.BallsCount = ballsAmount;
            var state = new SoldState(machine);

            state.Dispense();
            Assert.IsTrue(machine.GetQuartersController().HasQuarters());
            Assert.AreEqual(machine.GetQuartersController().GetQuartersCount(), (uint)1);
            Assert.AreEqual((uint)1, machine.BallsCount);
            Assert.AreEqual(machine.State, State.HasQuarter);
        }
        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);
        }