public void DispenseWithZeroBallsAndSomeQuartersTest() { var stringWriter = new StringWriter(); var result = new StringWriter(); var gumballMachine = new GumballMachineContext(1, stringWriter); var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" + $" { 0 } gumball{ ( 0 != 1 ? "s" : "" ) }" + $" { 1 } quarter{ ( 1 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_SOLD_OUT_STATE })"; var soldState = new SoldState(gumballMachine, stringWriter); var hasQuarterState = new HasQuarterState(gumballMachine, stringWriter); gumballMachine.InsertQuarter(); gumballMachine.InsertQuarter(); hasQuarterState.TurnCrank(); soldState.Dispense(); result.WriteLine(BaseConstants.INSERT_QUARTER_NO_QUARTER_STATE); result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(2)); result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(1)); result.WriteLine(BaseConstants.RELEASE_BALL); result.WriteLine(BaseConstants.DISPENSE_SOLD_STATE); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public void SetMachineInSoldStateWhenTurnCrank() { var machine = new TestGumballMachine(); var state = new HasQuarterState(machine); state.TurnCrank(); Assert.AreEqual((Enums.State)machine.State, Enums.State.Sold); }
public void TurnCrank_OneQuarterInMachine_MachineWithoutQuarter() { //Arrange _gumballMachineWithStateMock.SetupProperty(c => c.QuartersCount, 1u); _gumballMachineWithStateMock.Setup(c => c.SetSoldState()).Verifiable(); //Act _hasQuarterState.TurnCrank(); //Assert Assert.Equal(0u, _gumballMachineWithStateMock.Object.QuartersCount); _gumballMachineWithStateMock.Verify(c => c.SetSoldState()); }
public void TurnCrankTest() { var stringWriter = new StringWriter(); var result = new StringWriter(); var gumballMachine = new GumballMachineContext(3, stringWriter); var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" + $" { 3 } gumball{ ( 3 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_SOLD_STATE })"; var hasQuarterState = new HasQuarterState(gumballMachine, stringWriter); hasQuarterState.InsertQuarter(); hasQuarterState.TurnCrank(); result.WriteLine(BaseConstants.INSERT_QUARTER_HAS_QUARTER_STATE); result.WriteLine(BaseConstants.TURN_CRANK_HAS_QUARTER_STATE); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }
public void TurnCrankWithOneQuarterTest() { var stringWriter = new StringWriter(); var result = new StringWriter(); var gumballMachine = new GumballMachineContext(3, stringWriter); var gumballMachineStateString = $"(Mighty Gumball, Inc.C# - enabled Standing Gumball Model #2019 (with state)Inventory:" + $" { 3 } gumball{ ( 3 != 1 ? "s" : "" ) }" + $" { 0 } quarter{ ( 0 != 1 ? "s" : "" ) } " + $"Machine is { BaseConstants.TO_STRING_SOLD_STATE })"; var hasQuarterState = new HasQuarterState(gumballMachine, stringWriter); hasQuarterState.InsertQuarter(); hasQuarterState.TurnCrank(); result.WriteLine(MultiGumbalMachineConstants.GetInsertQuarterHasQuarterStateConst(1)); result.WriteLine(MultiGumbalMachineConstants.GetTurnCrankHasQuarterStateConst(0)); Assert.AreEqual(result.ToString(), stringWriter.ToString()); Assert.AreEqual(gumballMachineStateString, gumballMachine.ToString()); }