示例#1
0
        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);
        }
示例#2
0
        public void TestCreateInvalidAccount()
        {
            IBankService bankService = ServiceProvider.GetService <IBankService>();

            Account account = CreateTestAccount("username", "password");

            bankService.CreateAccount(account);

            Assert.Null(bankService.CreateAccount(account));
        }
示例#3
0
        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));
        }
示例#5
0
        public ActionResult <Account> CreateAccount([FromBody] Account account)
        {
            var accountCreated = _bankService.CreateAccount(account);

            if (accountCreated == null)
            {
                return(BadRequest());
            }
            return(Ok(accountCreated));
        }
示例#6
0
        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));
        }
示例#7
0
        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));
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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());
        }
示例#12
0
        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);
        }
示例#13
0
        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();
        }
示例#14
0
        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;
                    }
                }
            }
        }