public override string Execute(IUserSession userSession) { if (args.Length != 1) { throw new ArgumentException(ErrorMessages.IncorrectInput); } var accountNumber = args[0]; if (!userSession.IsLoggedIn()) { throw new ArgumentException(ErrorMessages.LoginFirst); } SavingsAccount targetAccount = null; var result = string.Empty; if (context.SavingsAccounts.Any(x => x.AccountNumber == accountNumber)) { targetAccount = context.SavingsAccounts.Where(x => x.AccountNumber == accountNumber).First(); targetAccount.AddInterest(); context.SaveChanges(); result = string.Format(SuccessMessages.AddInterest, accountNumber, targetAccount.Balance); } if (targetAccount == null) { throw new ArgumentException(string.Format(ErrorMessages.AccountDontExist, accountNumber)); } return(result); }
public void AddInterest() { // Arrange SavingsAccount bankAccount = new SavingsAccount("QA", "1234", 500.00M, 0.1M); // Act bankAccount.AddInterest(); // Assert Assert.AreEqual(bankAccount.Balance, 550.00M); }
public static void Main(string[] args) { BankAccount account = new BankAccount("hhaoa121321"); Console.WriteLine($"Account number: {account.AccountNumber}"); Console.WriteLine($"Account balance: {account.Balance}"); account.Deposit(200M); Console.WriteLine($"Account balance after deposit: {account.Balance}"); account.Withdraw(100M); Console.WriteLine($"Account balance after withdrawal: {account.Balance}"); Console.WriteLine($"Number of transactions: {account.NumberOfTransactions}"); IEnumerable <Transaction> transactions = account.GetTransactions(null, null); foreach (Transaction t in transactions) { Console.WriteLine($"Transaction: {t.DateOfTrans.ToString("dd/MM/yyyy")} -- {t.Amount} -- {t.TransactionType}"); } Console.WriteLine("\n"); SavingsAccount saccount = new SavingsAccount("oiejoiw6564", 0.02M); saccount.Deposit(300M); saccount.AddInterest(); saccount.Withdraw(50M); foreach (Transaction t in saccount.GetTransactions(null, null)) { Console.WriteLine($"Transaction: {t.DateOfTrans.ToString("dd/MM/yyyy")} -- {t.Amount} -- {t.TransactionType}"); } Console.ReadKey(); }
static void Main(string[] args) { BankAccount myBA = new BankAccount("123-12312312-99"); Console.WriteLine($"Account {myBA.AccountNumber} created..."); Console.WriteLine($"Balance is currently {myBA.Balance} Euro"); //Console.WriteLine($"Withdrawcost is {BankAccount._withdrawCost} Euro"); BankAccount myOBA = new BankAccount("123-12312312-99", 50); Console.WriteLine($"Account {myOBA.AccountNumber} created..."); Console.WriteLine($"Balance is currently {myOBA.Balance} Euro"); myBA.Deposit(1000); Console.WriteLine(myBA); myBA.Withdraw(200); Console.WriteLine(myBA); myBA.Withdraw(100); Console.WriteLine(myBA); var transactions = myBA.Transactions; foreach (var item in transactions) { Console.WriteLine($"{item.DateOfTransaction} -- {item.Amount} -- {item.TransactionType}"); } var mySA = new SavingsAccount("123-12312312-88", 0.01M); mySA.Deposit(1000); mySA.AddInterest(); mySA.Withdraw(20); Console.WriteLine("SavingsAccount: "); foreach (var item in mySA.Transactions) { Console.WriteLine($"{item.DateOfTransaction} -- {item.Amount} -- {item.TransactionType}"); } Console.ReadKey(); }
public void AddInterestChangesBalance() { _savingsAccount.AddInterest(); Assert.Equal(204, _savingsAccount.Balance); }