public void TestRegistersItselfAsObserverWithCoinPurse() { MockCoinPurse mockCoinPurse = new MockCoinPurse(); VendingDisplayController displayController = new VendingDisplayController(new TextBox(), mockCoinPurse); Assert.AreEqual(1, mockCoinPurse.NumberOfTimesRegisterObserverWasCalled); Assert.AreEqual(displayController, mockCoinPurse.RegisteredCoinPurseObservers[0]); }
public void TestProperties() { TextBox expectedTextBox = new TextBox(); MockCoinPurse expectedCoinPurse = new MockCoinPurse(); VendingDisplayController displayController = new VendingDisplayController(expectedTextBox, expectedCoinPurse); Assert.AreSame(expectedTextBox, displayController.Display); Assert.AreSame(expectedCoinPurse, displayController.CoinPurse); }
public void TestProperties() { MockCoinFactory expectedCoinFactory = new MockCoinFactory(); MockCoinPurse expectedCoinPurse = new MockCoinPurse(); MockCoinReturn expectedCoinReturn = new MockCoinReturn(); CoinAccepter coinAccepter = new CoinAccepter(expectedCoinFactory, expectedCoinPurse, expectedCoinReturn); Assert.AreSame(expectedCoinFactory, coinAccepter.CoinFactory); Assert.AreSame(expectedCoinPurse, coinAccepter.CoinPurse); Assert.AreSame(expectedCoinReturn, coinAccepter.CoinReturn); }
public void TestSetsCurrentPurseValueFormatedLikeMoneyWhenCoinPurseNotifiesAmountHasChanged(decimal purseValue, string expectedDisplayText) { TextBox displayTextBox = new TextBox(); MockCoinPurse mockCoinPurse = new MockCoinPurse {AmountAvailableToReturn = purseValue}; VendingDisplayController displayController = new VendingDisplayController(displayTextBox, mockCoinPurse); displayController.CoinPurseUpdated(); Assert.AreEqual(expectedDisplayText, displayTextBox.Text); }
public void TestAcceptAddsCoinReturnedByCoinFactoryToCoinPurseIfItHasValue() { MockCoinFactory mockCoinFactory = new MockCoinFactory(); MockCoinPurse mockCoinPurse = new MockCoinPurse(); MockCoin expectedCoin = new MockCoin {ValueToReturn = decimal.MaxValue}; mockCoinFactory.CoinToReturn = expectedCoin; CoinAccepter coinAccepter = new CoinAccepter(mockCoinFactory, mockCoinPurse, new MockCoinReturn()); coinAccepter.Accept(CoinSize.Tiny); Assert.AreEqual(1, mockCoinPurse.NumberOfTimesAddCoinWasCalled); Assert.AreEqual(1, mockCoinPurse.CoinsPassedToAddCoin.Count); Assert.AreEqual(expectedCoin, mockCoinPurse.CoinsPassedToAddCoin[0]); }
public void TestSetsDisplayTestBackToInitialMessageIfCoinPurseIsZero() { TextBox displayTextBox = new TextBox(); MockCoinPurse mockCoinPurse = new MockCoinPurse {AmountAvailableToReturn = 0.99m}; VendingDisplayController displayController = new VendingDisplayController(displayTextBox, mockCoinPurse); displayController.CoinPurseUpdated(); Assert.AreNotEqual("INSERT COINS", displayTextBox.Text); mockCoinPurse.AmountAvailableToReturn = 0; displayController.CoinPurseUpdated(); Assert.AreEqual("INSERT COINS", displayTextBox.Text); }
public void TestCoinWithNoValueIsPutIntoTheCoinReturnAndNotTheCoinPurse(decimal coinValue) { MockCoinFactory mockCoinFactory = new MockCoinFactory(); MockCoinPurse mockCoinPurse = new MockCoinPurse(); MockCoinReturn mockCoinReturn = new MockCoinReturn(); MockCoin mockCoin = new MockCoin {ValueToReturn = coinValue}; mockCoinFactory.CoinToReturn = mockCoin; CoinAccepter coinAccepter = new CoinAccepter(mockCoinFactory, mockCoinPurse, mockCoinReturn); coinAccepter.Accept(CoinSize.Large); Assert.AreSame(mockCoin, mockCoinReturn.CoinsPassedToAddCoin[0]); Assert.AreEqual(1, mockCoinReturn.NumberOfTimesAddCoinCalled); Assert.AreEqual(0, mockCoinPurse.NumberOfTimesAddCoinWasCalled); Assert.AreEqual(0, mockCoinPurse.Coins.Count); }
public void TestAcceptAddsCoinReturnedByCoinFactoryToCoinPurseIfItHasValue() { MockCoinFactory mockCoinFactory = new MockCoinFactory(); MockCoinPurse mockCoinPurse = new MockCoinPurse(); MockCoin expectedCoin = new MockCoin { ValueToReturn = decimal.MaxValue }; mockCoinFactory.CoinToReturn = expectedCoin; CoinAccepter coinAccepter = new CoinAccepter(mockCoinFactory, mockCoinPurse, new MockCoinReturn()); coinAccepter.Accept(CoinSize.Tiny); Assert.AreEqual(1, mockCoinPurse.NumberOfTimesAddCoinWasCalled); Assert.AreEqual(1, mockCoinPurse.CoinsPassedToAddCoin.Count); Assert.AreEqual(expectedCoin, mockCoinPurse.CoinsPassedToAddCoin[0]); }
public void TestCoinWithNoValueIsPutIntoTheCoinReturnAndNotTheCoinPurse(decimal coinValue) { MockCoinFactory mockCoinFactory = new MockCoinFactory(); MockCoinPurse mockCoinPurse = new MockCoinPurse(); MockCoinReturn mockCoinReturn = new MockCoinReturn(); MockCoin mockCoin = new MockCoin { ValueToReturn = coinValue }; mockCoinFactory.CoinToReturn = mockCoin; CoinAccepter coinAccepter = new CoinAccepter(mockCoinFactory, mockCoinPurse, mockCoinReturn); coinAccepter.Accept(CoinSize.Large); Assert.AreSame(mockCoin, mockCoinReturn.CoinsPassedToAddCoin[0]); Assert.AreEqual(1, mockCoinReturn.NumberOfTimesAddCoinCalled); Assert.AreEqual(0, mockCoinPurse.NumberOfTimesAddCoinWasCalled); Assert.AreEqual(0, mockCoinPurse.Coins.Count); }