public void TestOpenHomeLoanAccount() { ReadifyBank testBank = new ReadifyBank(); // Test for invalid customer name IAccount invalidName = testBank.OpenHomeLoanAccount("John123"); Assert.Null(invalidName); Assert.Empty(testBank.AccountList); // Test for valid home loan account customer IAccount john = testBank.OpenHomeLoanAccount("John"); Assert.Equal("John", john.CustomerName); Assert.Equal(0, john.Balance); Assert.StartsWith("LN-", john.AccountNumber); Assert.Matches("^LN-\\d{6}$", john.AccountNumber); Assert.NotEmpty(testBank.AccountList); Assert.Equal(1, testBank.AccountList.Count); // Add another 19 home loan accont foreach (int i in Enumerable.Range(1, 19)) { testBank.OpenHomeLoanAccount("LNCustomer", DateTimeOffset.Now.LocalDateTime); } Assert.Equal(20, testBank.AccountList.Count); }
public void TestPerformWithdrawal() { ReadifyBank testBank = new ReadifyBank(); // Test for invalid account testBank.PerformWithdrawal(null, 200, "withdrawwal 200."); Assert.Equal(0, testBank.TransactionLog.Count); IAccount john = testBank.OpenHomeLoanAccount("John"); testBank.PerformDeposit(john, 200, "deposit 200."); // Test for withdrawal amount exceeds balance testBank.PerformWithdrawal(john, 300, "withdrawal 300."); Assert.Equal(200, john.Balance); Assert.Equal(1, testBank.TransactionLog.Count); // Test for nomal circumstances testBank.PerformWithdrawal(john, 100, "withdrawal 100."); Assert.Equal(100, john.Balance); Assert.Same(john, testBank.TransactionLog.Last().Account); Assert.Equal(-100, testBank.TransactionLog.Last().Amount); Assert.Equal(john.Balance, testBank.TransactionLog.Last().Balance); Assert.Equal(2, testBank.TransactionLog.Count); }
private static void showCustomerInfo(IAccount account, ReadifyBank bank) { Console.WriteLine(string.Format("Customer {0} info:\nName: {0}, Account: {1}, " + "Balance: {2}\nOpened date: {3}\n", account.CustomerName, account.AccountNumber, account.Balance, account.OpenedDate)); }
private static void showTransactionInfo(IStatementRow transaction, ReadifyBank bank) { Console.WriteLine(string.Format("Transaction info: Account: {0}, Date: {1}, " + "Amount: {2}, Balance: {3}, Description: {4}", transaction.Account.AccountNumber, transaction.Date, transaction.Amount, transaction.Balance, transaction.Description)); }
public void TestGetMiniStatement() { ReadifyBank testBank = new ReadifyBank(); // Test for an account only have one transaction IAccount jill = testBank.OpenHomeLoanAccount("Jill"); testBank.PerformDeposit(jill, 100, "deposit 100."); IEnumerable <IStatementRow> miniStatementForJill = testBank.GetMiniStatement(jill); Assert.Equal(1, miniStatementForJill.Count()); Assert.Equal(100, miniStatementForJill.ToList()[0].Balance); // Test normal circumstances IAccount john = testBank.OpenHomeLoanAccount("John"); IAccount jack = testBank.OpenSavingsAccount("Jack"); foreach (int i in Enumerable.Range(1, 20)) { decimal depositAmount = (decimal)(i * 100); testBank.PerformDeposit(john, depositAmount, string.Format("deposit {0}.", depositAmount)); testBank.PerformDeposit(jack, depositAmount, string.Format("deposit {0}.", depositAmount)); } IEnumerable <IStatementRow> miniStatementForJohn = testBank.GetMiniStatement(john); Assert.Equal(5, miniStatementForJohn.Count()); decimal johnBalance = 12000; foreach (int i in Enumerable.Range(0, 5)) { Assert.Same(john, miniStatementForJohn.ToList()[i].Account); decimal amount = (16 + i) * 100; johnBalance += amount; Assert.Equal(amount, miniStatementForJohn.ToList()[i].Amount); Assert.Equal(johnBalance, miniStatementForJohn.ToList()[i].Balance); } // Test for invalid account IEnumerable <IStatementRow> miniStatementForNotExist = testBank.GetMiniStatement(null); Assert.Null(miniStatementForNotExist); }
public void TestPerformDeposit() { ReadifyBank testBank = new ReadifyBank(); // Test for invalid account testBank.PerformDeposit(null, 200, "deposit 200."); Assert.Equal(0, testBank.TransactionLog.Count); // Test for invalid deposit amount IAccount john = testBank.OpenHomeLoanAccount("John"); testBank.PerformDeposit(john, -200, "invalid deposit."); Assert.Equal(0, john.Balance); Assert.Equal(0, testBank.TransactionLog.Count); // Test for nomal circumstances testBank.PerformDeposit(john, 200, "deposit 200."); Assert.Equal(200, john.Balance); Assert.Same(john, testBank.TransactionLog.Last().Account); Assert.Equal(200, testBank.TransactionLog.Last().Amount); Assert.Equal(john.Balance, testBank.TransactionLog.Last().Balance); Assert.Equal(1, testBank.TransactionLog.Count); }
public void TestCloseAccount() { // Add two account ReadifyBank testBank = new ReadifyBank(); IAccount john = testBank.OpenHomeLoanAccount("John"); IAccount jack = testBank.OpenSavingsAccount("jack"); foreach (int i in Enumerable.Range(1, 20)) { decimal depositAmount = (decimal)(i * 100); testBank.PerformDeposit(john, depositAmount, string.Format("deposit {0}.", depositAmount)); testBank.PerformDeposit(jack, depositAmount, string.Format("deposit {0}.", depositAmount)); } // Test for close account jack IEnumerable <IStatementRow> allJackTransactions = testBank.CloseAccount(jack); Assert.Equal(1, testBank.AccountList.Count); Assert.Equal(-21000, testBank.TransactionLog.Last().Amount); Assert.Equal(0, testBank.TransactionLog.Last().Balance); foreach (IStatementRow transaction in allJackTransactions) { Assert.Same(jack, transaction.Account); } // Test for close account john IEnumerable <IStatementRow> allJohnTransactions = testBank.CloseAccount(john); Assert.Equal(0, testBank.AccountList.Count); Assert.Equal(-21000, testBank.TransactionLog.Last().Amount); Assert.Equal(0, testBank.TransactionLog.Last().Balance); foreach (IStatementRow transaction in allJohnTransactions) { Assert.Same(john, transaction.Account); } }
public void TestPerformTransfer() { ReadifyBank testBank = new ReadifyBank(); IAccount john = testBank.OpenHomeLoanAccount("John"); IAccount jack = testBank.OpenSavingsAccount("Jack"); testBank.PerformDeposit(john, 200, "deposit 200."); // Test for invalid recipient account testBank.PerformTransfer(john, null, 100, "Tranfer 100."); Assert.Equal(200, john.Balance); Assert.Equal(1, testBank.TransactionLog.Count); // Test for invlaid payer account testBank.PerformTransfer(null, john, 100, "Tranfer 100"); Assert.Equal(200, john.Balance); Assert.Equal(1, testBank.TransactionLog.Count); // Test for nomal circumstances testBank.PerformTransfer(john, jack, 100, "Tranfer 100 to jack."); Assert.Equal(100, john.Balance); Assert.Equal(100, jack.Balance); Assert.Equal(3, testBank.TransactionLog.Count); }
public void TestCalculateInterestToDate() { ReadifyBank testBank = new ReadifyBank(); IAccount john = testBank.OpenHomeLoanAccount("John"); testBank.PerformDeposit(john, 1000, "deposit 1000."); IAccount jack = testBank.OpenSavingsAccount("jack"); testBank.PerformDeposit(jack, 1000, "deposit 1000."); // Test for invalid toDate DateTimeOffset invalidToDate = DateTimeOffset.Now.LocalDateTime.AddDays(-60); decimal interestForJohn = testBank.CalculateInterestToDate(john, invalidToDate); decimal interestForJack = testBank.CalculateInterestToDate(jack, invalidToDate); Assert.Equal(-1, interestForJohn); Assert.Equal(-1, interestForJack); // Test for valid toDate const int ADD_DAYS = 60; DateTimeOffset toDate = DateTimeOffset.Now.LocalDateTime.AddDays(ADD_DAYS); interestForJohn = testBank.CalculateInterestToDate(john, toDate); decimal LNInterestRate = interestForJohn * 365 / ADD_DAYS / 1000; Assert.True(LNInterestRate - 0.0399m < 0.0001m); interestForJack = testBank.CalculateInterestToDate(jack, toDate); decimal SVInterestRate = interestForJack * 365 / 12 / ADD_DAYS / 1000; Assert.True(SVInterestRate - 0.06m < 0.0001m); // Test for invalid account decimal interestForNull = testBank.CalculateInterestToDate(null, toDate); Assert.Equal(-1, interestForNull); }
static void Main(string[] args) { ReadifyBank bank = new ReadifyBank(); IAccount john = bank.OpenSavingsAccount("John"); IAccount jack = bank.OpenHomeLoanAccount("Jack"); foreach (int i in Enumerable.Range(1, 9)) { bank.OpenSavingsAccount("SCVustomer"); bank.OpenHomeLoanAccount("LNCustomer"); } Console.WriteLine(string.Format("After open 20 account. Total account number: {0}\n", bank.AccountList.Count)); showCustomerInfo(john, bank); showCustomerInfo(jack, bank); foreach (int i in Enumerable.Range(1, 10)) { bank.PerformDeposit(john, 100, "deposit 100"); bank.PerformDeposit(jack, 50, "deposit 50"); } Console.WriteLine("After deposit:"); showCustomerInfo(john, bank); showCustomerInfo(jack, bank); foreach (int i in Enumerable.Range(1, 10)) { bank.PerformWithdrawal(john, 20, "withdraw 20"); bank.PerformWithdrawal(jack, 10, "withdraw 10"); } Console.WriteLine("After withdrawal:"); showCustomerInfo(john, bank); showCustomerInfo(jack, bank); bank.PerformTransfer(john, jack, 50, "lunch fee."); Console.WriteLine("After John transfer 50 to Jack:"); showCustomerInfo(john, bank); showCustomerInfo(jack, bank); Console.WriteLine("When John transfor amount exceeds balance:"); bank.PerformTransfer(john, jack, 800, "bill."); showCustomerInfo(john, bank); showCustomerInfo(jack, bank); Console.WriteLine("Calculate interest for 60 days for John and Jack:"); DateTimeOffset toDate = DateTimeOffset.Now.LocalDateTime.AddDays(60); decimal interestForJohn = bank.CalculateInterestToDate(john, toDate); decimal interestForJack = bank.CalculateInterestToDate(jack, toDate); Console.WriteLine(string.Format("The interest for John to 60 days later is: {0:C4}", interestForJohn)); Console.WriteLine(string.Format("The interest for Jack to 60 days later is: {0:C4}\n", interestForJack)); IEnumerable <IStatementRow> miniStatementOfJohn = bank.GetMiniStatement(john); IEnumerable <IStatementRow> miniStatementOfJack = bank.GetMiniStatement(jack); Console.WriteLine("Mini statement of John:"); foreach (IStatementRow transaction in miniStatementOfJohn) { showTransactionInfo(transaction, bank); } Console.WriteLine("\nMini statement of Jack:"); foreach (IStatementRow transaction in miniStatementOfJack) { showTransactionInfo(transaction, bank); } Console.WriteLine("\nNow close the account John:"); IEnumerable <IStatementRow> allTransactionOfJohn = bank.CloseAccount(john); foreach (IStatementRow transaction in allTransactionOfJohn) { showTransactionInfo(transaction, bank); } }