Example #1
0
        public void TestWithdrawMoney()
        {
            //Arrange
            const int     amount      = 100500;
            const decimal balance     = 200500;
            var           operationId = Guid.NewGuid();


            var allCash = new Money
            {
                Amount = 240000,
                Notes  = new Dictionary <PaperNote, int>
                {
                    { PaperNote.Twenty, 2000 },
                    { PaperNote.Fifty, 4000 }
                }
            };

            var resultCash = new Money
            {
                Amount = amount,
                Notes  = new Dictionary <PaperNote, int>
                {
                    { PaperNote.Fifty, 2010 }
                }
            };

            _cashProcessor.Cash.Returns(allCash);
            _cashProcessor.MinDenomination().Returns(PaperNote.Twenty);
            _cashProcessor.WithdrawMoney(amount).Returns(resultCash);
            _cardProcessor.GetCardBalance().Returns(balance);
            _cardProcessor.BlockAmount(amount).Returns(operationId);

            //Act
            var result = _atMachine.WithdrawMoney(amount);

            //Assert

            Received.InOrder(() =>
            {
                _cashProcessor.MinDenomination();
                _cardProcessor.GetCardBalance();
                _cardProcessor.BlockAmount(Arg.Is(amount));
                _cashProcessor.WithdrawMoney(Arg.Is(amount));
                _cardProcessor.WithdrawFromBlocked(Arg.Is(operationId));
            });

            Assert.Equal(resultCash, result);
        }
Example #2
0
        ///<summary>Withdraw money from ATM.</summary>
        ///<paramname="amount">Amount of money to withdraw.</param>
        public Money WithdrawMoney(int amount)
        {
            WithdrawalValidation(amount);

            var operationId = _cardProcessor.BlockAmount(amount);
            var money       = _cashProcessor.WithdrawMoney(amount);

            _cardProcessor.WithdrawFromBlocked(operationId);

            return(money);
        }