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 TestAmoutAvaibleReturnsValueOfAllCoinsInTheReturn()
        {
            CoinReturn coinReturn = new CoinReturn();

            decimal expectedValue = 4.00m;
            MockCoin mockCoinOne = new MockCoin() { ValueToReturn = expectedValue};

            coinReturn.AddCoin(mockCoinOne);

            Assert.AreEqual(expectedValue, coinReturn.AmountAvailable);
        }
        public void TestAddPutsCoinIntoCoinList()
        {
            CoinReturn coinReturn = new CoinReturn();
            MockCoin coinAdded = new MockCoin();

            coinReturn.AddCoin(coinAdded);
            Assert.AreEqual(new List<ICoin>() { coinAdded }, coinReturn.Coins);
        }
        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 TestClearEmptiesCoinList()
        {
            CoinReturn coinReturn = new CoinReturn();

            MockCoin firstCoinAdded = new MockCoin();
            MockCoin secondCoinAdded = new MockCoin();
            MockCoin thirdCoinAdded = new MockCoin();

            coinReturn.AddCoin(firstCoinAdded);
            coinReturn.AddCoin(secondCoinAdded);
            coinReturn.AddCoin(thirdCoinAdded);

            coinReturn.Clear();

            Assert.AreEqual(new List<ICoin>(), coinReturn.Coins);
        }
        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 TestAddPutsCoinIntoCoinListMultipleCoins()
        {
            CoinReturn coinReturn = new CoinReturn();

            MockCoin firstCoinAdded = new MockCoin();
            MockCoin secondCoinAdded = new MockCoin();
            MockCoin thirdCoinAdded = new MockCoin();

            List<ICoin> expectedCoins = new List<ICoin>()
            {
                firstCoinAdded,
                secondCoinAdded,
                thirdCoinAdded
            };

            coinReturn.AddCoin(firstCoinAdded);
            coinReturn.AddCoin(secondCoinAdded);
            coinReturn.AddCoin(thirdCoinAdded);

            Assert.AreEqual(expectedCoins, coinReturn.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 TestAmoutAvaibleReturnsValueOfAllCoinsInTheReturnMulitpleCoins()
        {
            CoinReturn coinReturn = new CoinReturn();

            MockCoin mockCoinOne = new MockCoin() {ValueToReturn = 1.00m};
            MockCoin mockCoinTwo = new MockCoin() {ValueToReturn = 99.28m};
            MockCoin mockCoinThree = new MockCoin() {ValueToReturn = 123.123m};

            decimal expectedValue = mockCoinOne.ValueToReturn + mockCoinTwo.ValueToReturn + mockCoinThree.ValueToReturn;

            coinReturn.AddCoin(mockCoinOne);
            coinReturn.AddCoin(mockCoinTwo);
            coinReturn.AddCoin(mockCoinThree);

            Assert.AreEqual(expectedValue, coinReturn.AmountAvailable);
        }
        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);
        }