public void WithDraw(BankAccount account, decimal amountToWithdraw) { ValidateWithDrawAccount(account, amountToWithdraw); account.WithDraw(amountToWithdraw); _repository.Save(account); }
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); }
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)); }
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!"); } }
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 = "" }; }