Exemplo n.º 1
0
        public void EjectQuarter()
        {
            switch (_state)
            {
            case State.SoldOut:
                // _textWriter.WriteLine( BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE );
                if (!_quarterCounter.IsEmptyCounter())
                {
                    _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterSoldOutStateConst(_quarterCounter.QuarterAmount));
                    _quarterCounter.Zeroize();
                }
                else
                {
                    _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE);
                }
                break;

            case State.NoQuarter:
                _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_NO_QUARTER_STATE);
                break;

            case State.HasQuarter:
                _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterHasQuarterStateConst(_quarterCounter.QuarterAmount));
                _quarterCounter.Zeroize();
                _state = State.NoQuarter;
                break;

            case State.Sold:
                _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_STATE);
                break;
            }
        }
Exemplo n.º 2
0
 public void EjectQuarter()
 {
     if (!_gumballMachine.QuarterCounter.IsEmptyCounter())
     {
         _textWriter.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterSoldOutStateConst(_gumballMachine.QuarterCounter.QuarterAmount));
         _gumballMachine.QuarterCounter.Zeroize();
     }
     else
     {
         _textWriter.WriteLine(BaseConstants.EJECT_QUARTER_SOLD_OUT_STATE);
     }
 }
Exemplo n.º 3
0
        public void EjectQuarterWithSomeQuartersTest()
        {
            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_HAS_QUARTER_STATE })";
            var soldOutState = new SoldOutState(gumballMachine, stringWriter);

            gumballMachine.InsertQuarter();
            gumballMachine.InsertQuarter();
            soldOutState.EjectQuarter();
            result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE);
            result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2));
            result.WriteLine(MultiGumbalMachineConstants.GetEjectQuarterSoldOutStateConst(2));

            Assert.AreEqual(result.ToString(), stringWriter.ToString());
            Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString());
        }