public GumMachine(int balls, IOutputWritter writter) { _balls = balls; _writter = writter; SoldOut = new SoldOutState(this,_writter); NoPenny = new NoPennyState(this, _writter); Sold = new SoldState(this, _writter); HasPenny = new HasPennyState(_writter, this); CurrentState = _balls<=0 ? SoldOut : NoPenny; }
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; } }
public GumballMachine(int numberOfGumballs) { Count = numberOfGumballs; if (Count > 0) { State = new NoQuarterState(this); } else { State = new SoldOutState(this); } }
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 soldOutState = new SoldOutState(gumballMachine, stringWriter); Assert.AreEqual(soldOutState.ToString(), BaseConstants.TO_STRING_SOLD_OUT_STATE); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public GumballMachine(int count) { this.Count = count; SoldOutState = new SoldOutState(this); SoldState = new SoldState(this); HasCoinState = new HasCoinState(this); NoCoinState = new NoCoinState(this); WinnerState = new WinnerState(this); CurrentState = Count > 0 ? NoCoinState : SoldOutState; }
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; } }
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; } }
public void DispenseTest() { 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 soldOutState = new SoldOutState(gumballMachine, stringWriter); soldOutState.Dispense(); result.WriteLine(BaseConstants.DISPENSE_SOLD_OUT_STATE); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public void ReFillWithSomeBallsTest() { var stringWriter = new StringWriter(); var result = new StringWriter(); var gumballMachine = new GumballMachineContext(0, stringWriter); var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" + $" { 10 } gumball{ ( 10 != 1 ? "s" : "" ) }" + $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_NO_QUARTER_STATE })"; var soldOutState = new SoldOutState(gumballMachine, stringWriter); soldOutState.ReFill(10); result.WriteLine(MultiGumbalMachineConstants.GetReFillSoldOutStateConst(10)); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public GumballMachine(int count) { noQarterState = new NoQarterState(this); hasQuarterState = new HasQuarterState(this); soldState = new SoldState(this); soldOutState = new SoldOutState(this); winnerState = new WinnerState(this); this.count = count; if (count > 0) { setState(noQarterState); } else { setState(soldOutState); } }
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()); }
public SoldOutStateTest() { _gumballMachineWithStateMock = new Mock <GumballMachineWithStateContext>(); _soldOutState = new SoldOutState(_gumballMachineWithStateMock.Object); }