internal static void CreateDefaultAccounts(IBankService bankService) { Account firstDefault = new Account() { AccountId = random.Next(), AccountNumber = random.Next(), AccountHolder = "Default One", SecondaryHolder = "No one", Balance = 200.0, Password = "******", Username = "******" }; Account secondDefault = new Account() { AccountId = random.Next(), AccountNumber = random.Next(), AccountHolder = "Default two", SecondaryHolder = "No one", Balance = 100.0, Username = "******", Password = "******" }; bankService.CreateAccount(firstDefault); bankService.CreateAccount(secondDefault); }
public void TestCreateInvalidAccount() { IBankService bankService = ServiceProvider.GetService <IBankService>(); Account account = CreateTestAccount("username", "password"); bankService.CreateAccount(account); Assert.Null(bankService.CreateAccount(account)); }
public void GetAccountById() { IBankService bankService = ServiceProvider.GetService <IBankService>(); Account account = CreateTestAccount("username", "password"); bankService.CreateAccount(account); Account account2 = CreateTestAccount("usernameone", "passwordtwo"); bankService.CreateAccount(account2); Account actualAccountOne = bankService.GetAccount(account.AccountId); Account actualAccounTwo = bankService.GetAccount(account2.AccountId); Assert.Equal(account, actualAccountOne); Assert.Equal(account2, actualAccounTwo); }
public IHttpActionResult AddAccount() { var user = _userRepository.Query().First(); var account = _bankService.CreateAccount(user); _uow.Commit(); return(OkResult(account)); }
public ActionResult <Account> CreateAccount([FromBody] Account account) { var accountCreated = _bankService.CreateAccount(account); if (accountCreated == null) { return(BadRequest()); } return(Ok(accountCreated)); }
public async Task <IActionResult> Register([FromBody] AccountViewModel accountViewModel) { if (!ModelState.IsValid) { return(BadRequest()); } var user = await _bankService.CreateAccount(accountViewModel.UserId); return(CreatedAtAction(nameof(Get), new { id = user.UserId }, user)); }
public void TestCreateAccount() { IBankService bankService = ServiceProvider.GetService <IBankService>(); // Create test account and add to the service Account account = CreateTestAccount("username", "password"); bankService.CreateAccount(account); // verify that the account was added. Assert.Equal(account, bankService.GetAccount(account.AccountId)); }
public void TestDepositIntoAccount() { IBankService bankService = ServiceProvider.GetService <IBankService>(); Account account = CreateTestAccount("username", "password"); bankService.CreateAccount(account); Transactions transactions = CreateTestDepositTransaction(account, 100); double expectedBalance = account.Balance + transactions.TransactionAmount; bankService.DepositIntoAccount(account.AccountId, transactions); Assert.Equal(account.Balance, expectedBalance); }
public void TestOverWithdrawFromAccount() { IBankService bankService = ServiceProvider.GetService <IBankService>(); string expected = "Failed"; double originalBalance = 200.0; Account account = CreateTestAccount("username", "password"); bankService.CreateAccount(account); Transactions transactions = CreateTestWithdrawTransaction(account, 1000); bankService.WithdrawlFromAccount(account.AccountId, transactions); Transactions failedTransaction = bankService.GetTransaction(transactions.TransactionId); Assert.Equal(failedTransaction.TransactionStatus, expected); Assert.Equal(account.Balance, originalBalance); }
public void TestGetAllTransactionsForAccount() { int expected = 1; IBankService bankService = ServiceProvider.GetService <IBankService>(); Account account = CreateTestAccount("username", "password"); bankService.CreateAccount(account); Account account2 = CreateTestAccount("usernameone", "passwordtwo"); Transactions transactionsOne = CreateTestDepositTransaction(account, 100); Transactions transactionsTwo = CreateTestDepositTransaction(account2, 100); bankService.CreateTransaction(transactionsOne); bankService.CreateTransaction(transactionsTwo); List <Transactions> transactionList = bankService.GetAllTransactionsForAccount(account.AccountId).ToList(); Assert.Equal(expected, transactionList.Count); }
public AccountDTO CreateCustomer(AccountForCreateDTO accountDTO) { Bank bank = _service.GetBankById(accountDTO.BankId); if (bank == null) { throw new BankException("Bank does not exist"); } Customer customer = _service.GetCustomerById(accountDTO.CustomerId); if (customer == null) { throw new BankException("Customer does not exist"); } Account account = _service.CreateAccount(bank, customer); _service.Save(); return(account.ToDTO()); }
internal static Account CreateNewAccountFromUser(IBankService bankService) { string username = null; string password = null; Account newAccount = null; Console.WriteLine("Enter a username: "******"Enter a password: "******"Enter the primary account holder : "); string accountHolder = Console.ReadLine(); Account account = HelperFunctions.CreateAccountObject(username, password, accountHolder); newAccount = bankService.CreateAccount(account); if (newAccount == null) { Console.WriteLine("Invalid account, please try again."); } return(newAccount); }
static void Main(string[] args) { service.CreateAccount( new Account { AccountType = AccountType.Base, Balance = 300, FirstName = "Vasya", LastName = "Pupkin" }); service.CreateAccount( new Account { AccountType = AccountType.Gold, Balance = 500, FirstName = "pasha", LastName = "vaskin" }); service.CreateAccount( new Account { AccountType = AccountType.Silver, Balance = 400, FirstName = "sasha", LastName = "pashkin" }); var account = service.GetAccounts(); foreach (var item in account) { Console.WriteLine(item); } Console.WriteLine("Add balance"); foreach (var item in account) { service.AddBalance(item.Id, 50); } foreach (var item in account) { Console.WriteLine(item); } Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine("Remove balance"); foreach (var item in account) { service.RemoveBalance(item.Id, 50); } foreach (var item in account) { Console.WriteLine(item); } Console.ReadKey(); }
static void Main(string[] args) { // Start up and create defaults. IBankService bankService = StartUp.GetConfiguredServices(); StartUp.CreatePreconfiguredAccounts(bankService); string username; string password; // Welcome message. DisplayMessaging.WelcomeMessage(); string createOrNot = Console.ReadLine().ToLower(); if (createOrNot.Equals("create")) { Account newAccount = null; while (newAccount == null) { newAccount = DisplayMessaging.CreateNewAccountFromUser(bankService); } } // User selection and interactions. Selections convertedInput; while (true) { // User must log into an account first. Console.WriteLine("Please log into an account"); Console.WriteLine("Enter username: "******"Enter password: "******"Amount to withdraw from account: "); input = Console.ReadLine(); while (!Int32.TryParse(input, out intValue)) { Console.WriteLine("Not a valid number to deposit"); Console.WriteLine("Amount to withdraw from account: "); input = Console.ReadLine(); } Transactions transactionWithdraw = HelperFunctions.CreateTransaction((int)userKey, intValue, "Withdraw"); bankService.WithdrawlFromAccount((int)userKey, transactionWithdraw); break; case Selections.DepositIntoAccount: Console.WriteLine("Amount to deposit into account: "); input = Console.ReadLine(); while (!Int32.TryParse(input, out intValue)) { Console.WriteLine("Not a valid number to deposit"); Console.WriteLine("Amount to deposit into account: "); input = Console.ReadLine(); } Transactions transactionDeposit = HelperFunctions.CreateTransaction((int)userKey, intValue, "Deposit"); bankService.DepositIntoAccount((int)userKey, transactionDeposit); break; case Selections.SeeTransactionHistory: IEnumerable <Transactions> transactionHistory = bankService.GetAllTransactionsForAccount((int)userKey); DisplayMessaging.PrettyDisplayTransactions(transactionHistory); break; case Selections.CreateAccount: Account accountToCreate = DisplayMessaging.CreateNewAccountFromUser(bankService); Account createdAccount = bankService.CreateAccount(accountToCreate); break; case Selections.LogOut: if (bankService.Logout()) { userKey = 0; account = null; } break; default: DisplayMessaging.InvalidInput(); break; } } } }