コード例 #1
1
        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);
        }
コード例 #2
0
        public void TestAddPutsCoinIntoCoinList()
        {
            CoinPurse coinPurse = new CoinPurse();
            MockCoin coinAdded = new MockCoin();

            coinPurse.AddCoin(coinAdded);
            Assert.AreEqual(new List<ICoin>() {coinAdded}, coinPurse.Coins);
        }
コード例 #3
0
        public void Accept(CoinSize coinSize)
        {
            ICoin receivedCoin = CoinFactory.BuildCoin(coinSize);

            if (receivedCoin.Value >= FiveCents)
            {
                CoinPurse.AddCoin(receivedCoin);
            }
            else
            {
                CoinReturn.AddCoin(receivedCoin);
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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]);
        }
コード例 #7
0
 public void TestCoinPurseStartsWithEmptyCoinList()
 {
     CoinPurse coinPurse = new CoinPurse();
     Assert.AreEqual(new List<ICoin>(), coinPurse.Coins);
 }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }