public void TestAmountAvailableReturnsTotalValueOfCoinsInPurse() { CoinPurse coinPurse = new CoinPurse(); decimal expectedValueOfAllCoins = 5.55m; MockCoin coinAdded = new MockCoin() {ValueToReturn = expectedValueOfAllCoins}; coinPurse.AddCoin(coinAdded); Assert.AreEqual(expectedValueOfAllCoins, coinPurse.AmountAvailable); }
public void TestAddPutsCoinIntoCoinList() { CoinPurse coinPurse = new CoinPurse(); MockCoin coinAdded = new MockCoin(); coinPurse.AddCoin(coinAdded); Assert.AreEqual(new List<ICoin>() {coinAdded}, coinPurse.Coins); }
public void Accept(CoinSize coinSize) { ICoin receivedCoin = CoinFactory.BuildCoin(coinSize); if (receivedCoin.Value >= FiveCents) { CoinPurse.AddCoin(receivedCoin); } else { CoinReturn.AddCoin(receivedCoin); } }
public void TestAddPutsCoinIntoCoinListMultipleCoins() { CoinPurse coinPurse = new CoinPurse(); MockCoin firstCoinAdded = new MockCoin(); MockCoin secondCoinAdded = new MockCoin(); MockCoin thirdCoinAdded = new MockCoin(); List<ICoin> expectedCoins = new List<ICoin>() { firstCoinAdded, secondCoinAdded, thirdCoinAdded }; coinPurse.AddCoin(firstCoinAdded); coinPurse.AddCoin(secondCoinAdded); coinPurse.AddCoin(thirdCoinAdded); Assert.AreEqual(expectedCoins, coinPurse.Coins); }
public void TestAmountAvailableReturnsTotalValueOfCoinsInPurseMultipleCoins() { CoinPurse coinPurse = new CoinPurse(); decimal expectedValueOfAllCoins = 0; const decimal firstCoinValue = 1.25m; MockCoin firstCoinAdded = new MockCoin() { ValueToReturn = firstCoinValue }; expectedValueOfAllCoins += firstCoinValue; const decimal secondCoinValue = 0.25m; MockCoin secondCoinAdded = new MockCoin() { ValueToReturn = secondCoinValue }; expectedValueOfAllCoins += secondCoinValue; const decimal thirdCoinValue = 4.25m; MockCoin thirdCoinAdded = new MockCoin() { ValueToReturn = thirdCoinValue }; expectedValueOfAllCoins += thirdCoinValue; coinPurse.AddCoin(firstCoinAdded); coinPurse.AddCoin(secondCoinAdded); coinPurse.AddCoin(thirdCoinAdded); Assert.AreEqual(expectedValueOfAllCoins, coinPurse.AmountAvailable); }
public void TestRegisterObserverAddsToObserverList() { CoinPurse coinPurse = new CoinPurse(); MockCoinPurseObserver mockCoinPurseObserver = new MockCoinPurseObserver(); coinPurse.RegisterObserver(mockCoinPurseObserver); Assert.AreEqual(1, coinPurse.Observers.Count); Assert.AreEqual(mockCoinPurseObserver, coinPurse.Observers[0]); }
public void TestCoinPurseStartsWithEmptyCoinList() { CoinPurse coinPurse = new CoinPurse(); Assert.AreEqual(new List<ICoin>(), coinPurse.Coins); }
public void TestClearNotifiesObservers() { CoinPurse coinPurse = new CoinPurse(); MockCoin mockCoin = new MockCoin(); MockCoinPurseObserver mockCoinPurseObserver = new MockCoinPurseObserver(); coinPurse.RegisterObserver(mockCoinPurseObserver); coinPurse.Clear(); Assert.AreEqual(1, mockCoinPurseObserver.NumberOfTimesCoinPurseUpdatedCalled); }
public void TestClearReturnsAllCoinsAndEmptiesPurse() { CoinPurse coinPurse = new CoinPurse(); MockCoin mockCoin = new MockCoin(); coinPurse.AddCoin(mockCoin); List<ICoin> coinsReturnedFromClear = coinPurse.Clear(); Assert.AreEqual(1, coinsReturnedFromClear.Count); Assert.AreEqual(mockCoin, coinsReturnedFromClear[0]); Assert.AreEqual(0, coinPurse.Coins.Count); }
public void TestUpdatesOberserversWhenCoinIsAddedToCoinPurse() { CoinPurse coinPurse = new CoinPurse(); MockCoinPurseObserver mockCoinPurseObserverOne = new MockCoinPurseObserver(); MockCoinPurseObserver mockCoinPurseObserverTwo = new MockCoinPurseObserver(); coinPurse.RegisterObserver(mockCoinPurseObserverOne); coinPurse.RegisterObserver(mockCoinPurseObserverTwo); coinPurse.AddCoin(new MockCoin()); Assert.AreEqual(1, mockCoinPurseObserverOne.NumberOfTimesCoinPurseUpdatedCalled); Assert.AreEqual(1, mockCoinPurseObserverTwo.NumberOfTimesCoinPurseUpdatedCalled); }