public void Bank_Deposit_Currency_Conversion_Fails() { var account0042 = new Account { AccountNumber = "0042", Balance = new Currency { Amount = 100, Type = CurrencyType.MXN } }; var accountFactoryMock = new Mock <IAccountFactory>(); accountFactoryMock .Setup(x => x.GetAccount(account0042.AccountNumber)) .Returns(account0042); var currencyActions = new CurrencyActions(); var sut = new Bank(accountFactoryMock.Object, currencyActions); var result = sut.Deposit(new DepositRequest { Currency = new Currency { Amount = 300, Type = CurrencyType.USD }, AccountNumber = account0042.AccountNumber }); Assert.IsTrue(result.IsError); Assert.AreEqual("We do not support converting USD to MXN.", result.Errors.First()); }
public void Bank_Withdraw_Insufficient_Funds_Fails() { var account0042 = new Account { AccountNumber = "0042", Balance = new Currency { Amount = 100, Type = CurrencyType.CAD } }; var accountFactoryMock = new Mock <IAccountFactory>(); accountFactoryMock .Setup(x => x.GetAccount(account0042.AccountNumber)) .Returns(account0042); var currencyActions = new CurrencyActions(); var sut = new Bank(accountFactoryMock.Object, currencyActions); var result = sut.Withdraw(new WithdrawRequest { Currency = new Currency { Amount = 300, Type = CurrencyType.USD }, AccountNumber = account0042.AccountNumber }); Assert.IsTrue(result.IsError); Assert.AreEqual("Cannot withdraw more than the balance of the account.", result.Errors.First()); }
public void Bank_Withdraw_Deposit_And_Transfer_Succeeds() { var accountFactoryMock = new Mock <IAccountFactory>(); accountFactoryMock .Setup(x => x.GetAccount(this._account0123.AccountNumber)) .Returns(this._account0123); accountFactoryMock .Setup(x => x.GetAccount(this._account0456.AccountNumber)) .Returns(this._account0456); var currencyActions = new CurrencyActions(); var sut = new Bank(accountFactoryMock.Object, currencyActions); sut.Withdraw(new WithdrawRequest { Currency = new Currency { Amount = 70, Type = CurrencyType.USD }, AccountNumber = this._account0123.AccountNumber }).AssertOk(); Assert.AreEqual(10, this._account0123.Balance.Amount); sut.Deposit(new DepositRequest { Currency = new Currency { Amount = 23789, Type = CurrencyType.USD }, AccountNumber = this._account0456.AccountNumber }).AssertOk(); Assert.AreEqual(112578, this._account0456.Balance.Amount); sut.Transfer(new TransferRequest { Currency = new Currency { Amount = 23.75m, Type = CurrencyType.CAD }, SourceAccountNumber = this._account0456.AccountNumber, DestinationAccountNumber = this._account0123.AccountNumber }).AssertOk(); Assert.AreEqual(33.75m, this._account0123.Balance.Amount); Assert.AreEqual(112554.25m, this._account0456.Balance.Amount); }
public void Bank_Withdraw_Transfer_And_Deposit_Succeeds() { var accountFactoryMock = new Mock <IAccountFactory>(); accountFactoryMock .Setup(x => x.GetAccount(this._account1010.AccountNumber)) .Returns(this._account1010); accountFactoryMock .Setup(x => x.GetAccount(this._account5500.AccountNumber)) .Returns(this._account5500); var currencyActions = new CurrencyActions(); var sut = new Bank(accountFactoryMock.Object, currencyActions); sut.Withdraw(new WithdrawRequest { Currency = new Currency { Amount = 5000, Type = CurrencyType.CAD }, AccountNumber = this._account5500.AccountNumber }).AssertOk(); Assert.AreEqual(10000, this._account5500.Balance.Amount); sut.Transfer(new TransferRequest { Currency = new Currency { Amount = 7300, Type = CurrencyType.CAD }, SourceAccountNumber = this._account1010.AccountNumber, DestinationAccountNumber = this._account5500.AccountNumber }).AssertOk(); Assert.AreEqual(125, this._account1010.Balance.Amount); Assert.AreEqual(17300, this._account5500.Balance.Amount); sut.Deposit(new DepositRequest { Currency = new Currency { Amount = 13726, Type = CurrencyType.MXN }, AccountNumber = this._account1010.AccountNumber }).AssertOk(); Assert.AreEqual(1497.6m, this._account1010.Balance.Amount); }
public void Bank_Deposit_Plus_Withdraw_Succeeds() { var accountFactoryMock = new Mock <IAccountFactory>(); accountFactoryMock .Setup(x => x.GetAccount(this._account2001.AccountNumber)) .Returns(this._account2001); var currencyActions = new CurrencyActions(); var sut = new Bank(accountFactoryMock.Object, currencyActions); sut.Withdraw(new WithdrawRequest { Currency = new Currency { Amount = 5000, Type = CurrencyType.MXN }, AccountNumber = this._account2001.AccountNumber }).AssertOk(); Assert.AreEqual(34500, this._account2001.Balance.Amount); sut.Withdraw(new WithdrawRequest { Currency = new Currency { Amount = 12500, Type = CurrencyType.USD }, AccountNumber = this._account2001.AccountNumber }).AssertOk(); Assert.AreEqual(9500, this._account2001.Balance.Amount); sut.Deposit(new DepositRequest { Currency = new Currency { Amount = 300, Type = CurrencyType.CAD }, AccountNumber = this._account2001.AccountNumber }).AssertOk(); Assert.AreEqual(9800, this._account2001.Balance.Amount); }
public void Bank_Deposit_Succeeds() { var accountFactoryMock = new Mock <IAccountFactory>(); accountFactoryMock .Setup(x => x.GetAccount(this._account1234.AccountNumber)) .Returns(this._account1234); var currencyActions = new CurrencyActions(); var sut = new Bank(accountFactoryMock.Object, currencyActions); sut.Deposit(new DepositRequest { Currency = new Currency { Amount = 300, Type = CurrencyType.USD }, AccountNumber = this._account1234.AccountNumber }).AssertOk(); Assert.AreEqual(700, this._account1234.Balance.Amount); }