Example #1
0
        public void WithDraw(BankAccount account, decimal amountToWithdraw)
        {
            ValidateWithDrawAccount(account, amountToWithdraw);

            account.WithDraw(amountToWithdraw);

            _repository.Save(account);
        }
Example #2
0
        public void Deposit(BankAccount account, decimal amountToDeposit)
        {
            ValidateDepositAccount(account, amountToDeposit);

            account.Deposit(amountToDeposit);

            _repository.Save(account);
        }
        public void Setup()
        {
            _httpContext.Setup(ctx => ctx.Response).Returns(_httpResponse.Object);

            _sut = new BankAccountHandler(new BankAccountService(_repository.Object));

             _account = new BankAccount(1000) { Id = 1 };
             _repository.Setup(rep => rep.GetById(It.IsAny<int>())).Returns(_account);
        }
Example #4
0
 public void Change(BankAccount account, decimal amount)
 {
     if (amount < 0)
     {
         WithDraw(account, Math.Abs(amount));
     }
     else
     {
         Deposit(account, amount);
     }
 }
        public void ItCanStoreBankAccounts()
        {
            // Arrange
            var account = new BankAccount(balance:5000);

            // Act
            _sut.Save(account);

            // Assert
            _session.Verify(session => session.Store(account), Times.Once());
            _session.Verify(session => session.SaveChanges(), Times.Once());
        }
        public void ItShouldBeAbleToWithDrawFromAnAccount()
        {
            //Arrange
            var account = new BankAccount(balance: 1000);
            const int expected = 600;

            //Act
            _sut.WithDraw(account, 400);

            //Assert
            Assert.That(account.Balance, Is.EqualTo(expected));
            _repository.Verify(repository => repository.Save(account));
        }
        public void ItThrowsErrorIfTryingToDepositAmountSmallerOrLessThanZero()
        {
            var account = new BankAccount(balance: 400);

            Assert.Throws<InvalidOperationException>(() => _sut.Deposit(account, -1));
            Assert.Throws<InvalidOperationException>(() => _sut.Deposit(account, 0));
        }
        public void ItThrowsErrorIfTheBalancIsToSmallForTheWithdraw()
        {
            var account = new BankAccount(balance: 400);

            Assert.Throws<InvalidOperationException>(() => _sut.WithDraw(account, 500));
        }
Example #9
0
        private static void ValidateWithDrawAccount(BankAccount account, decimal amountToWithDraw)
        {
            Assert.NotNull(account);

            ValidateBiggerThanZero(amountToWithDraw);

            if (account.Balance < amountToWithDraw)
            {
                throw new InvalidOperationException("The balance cannot be smaller than the amount to withdraw!");
            }
        }
Example #10
0
        private static void ValidateDepositAccount(BankAccount account, decimal amountToDeposit)
        {
            Assert.NotNull(account);

            ValidateBiggerThanZero(amountToDeposit);
        }
        public void Setup()
        {
            _sut = IoC.Resolve<IBankAccountRepository>();

            _account = new BankAccount(3500) { Name = "" };
        }