public static void Main() { BankAccount ba = new BankAccount("Mr. Bryan Walton", 11.99); ba.Credit(5.77); ba.Debit(11.22); Console.WriteLine("Current balance is ${0}", ba.Balance); }
public void Credit_Simple_Amount_UpdatesBalance() { // arrange double beginningBalance = 11.99; double creditAmount = 4.55; double expected = 16.53; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); // act account.Credit(creditAmount); // assert double actual = account.Balance; Assert.AreEqual(expected, actual, 0.01, "Account not credited correctly"); }
public BankAccount ReadAccount(string name) { BankAccount account = null; var contents = fileWriter.Read(name); var both = contents.Split('|'); if (both.Length == 2) { double balance = 0; if (double.TryParse(both[1], out balance)) { account = new BankAccount(both[0], balance); } } return account; }
public void Debit_WithValidAmount_UpdatesBalance() { // arrange double beginningBalance = 11.99; double debitAmount = 4.55; double expected = 7.44; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); // act account.Debit(debitAmount); // assert double actual = account.Balance; Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly"); }
public void DebitAccount_WriteToFile_ThenRead() { // arrange double beginningBalance = 11.99; double debitAmount = 4.55; double expected = 7.44; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); account.Debit(debitAmount); // act IFileWriter writer = new FileWriter(); BankAccountWriter baw = new BankAccountWriter(writer); baw.WriteAccount(account); // assert var readAccount = baw.ReadAccount(account.Name); Assert.AreEqual(readAccount.Balance, account.Balance); Assert.AreEqual(readAccount.Name, account.Name); }
public void Debit_WhenAmountIsMoreThanBalance_ShouldThrowArgumentOutOfRange() { // arrange double beginningBalance = 11.99; double debitAmount = 20.0; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); // act try { account.Debit(debitAmount); } catch (ArgumentOutOfRangeException e) { // assert StringAssert.Contains(e.Message, BankAccount. DebitAmountExceedsBalanceMessage); return; } Assert.Fail("No exception was thrown."); }
public void DebitAccount_WriteToFile_ThenRead_Mocked() { // arrange double beginningBalance = 11.99; double debitAmount = 4.55; double expected = 7.44; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); account.Debit(debitAmount); // act var writer = new Moq.Mock<IFileWriter>(); writer.Setup(w => w.Write(Moq.It.IsAny<string>(), Moq.It.IsAny<string>())); writer.Setup(w => w.Read(Moq.It.IsAny<string>())).Returns(String.Format("{0}|{1}", account.Name, account.Balance)); BankAccountWriter baw = new BankAccountWriter(writer.Object); baw.WriteAccount(account); // assert var readAccount = baw.ReadAccount(account.Name); Assert.AreEqual(readAccount.Balance, account.Balance); Assert.AreEqual(readAccount.Name, account.Name); }
public void WriteAccount(BankAccount account) { fileWriter.Write(account.Name, String.Format("{0}|{1}", account.Name, account.Balance)); }
public void Debit_And_Credit_Multi_Threaded() { // arrange double beginningBalance = 10; double debitAmount = -1; double creditAmount = 1; double expected = 10; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); // act List<Task> tasks = new List<Task>(); for (int i = 0; i < 10; i++) { tasks.Add(Task.Run(() => account.Debit(debitAmount))); tasks.Add(Task.Run(() => account.Credit(creditAmount))); } Task.WaitAll(tasks.ToArray()); // assert double actual = account.Balance; Assert.AreEqual(expected, actual, 0.01, "Account balance is not correct"); }
public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange() { // arrange double beginningBalance = 11.99; double debitAmount = -100.00; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); // act account.Debit(debitAmount); // assert is handled by ExpectedException }
public Credit(string number, BankAccount bankAccount) : base(number) { this.bankAccountConnectedWithCredit = bankAccount; }
static void writeAccount(BankAccount account) { }
static void decrementAmount(BankAccount account, double money) { }
static void incrementAmount(BankAccount account, double money) { account.amount = account.amount + money; }
public abstract bool Transfer(BankAccount toAccount, double amount);