Esempio n. 1
0
        private static void RandomTransactionInType(List <Account> accounts, TransactionType type, DateTime dateTime, int numOfTransactions)
        {
            var random = new Random();

            // for each account
            foreach (var acc in accounts)
            {
                AccountAdapter accountAdapter = new AccountAdapter(acc);
                switch (type)
                {
                case TransactionType.Deposit:
                    RandomDeposit();
                    break;

                case TransactionType.Withdraw:
                    RandomWithdraw();
                    break;

                case TransactionType.Transfer:
                    RandomTransfer();
                    break;
                }

                void RandomDeposit()
                {
                    for (int i = 0; i < numOfTransactions; i++)
                    {
                        accountAdapter.DepositWithSpecTime(random.Next(20, 1000), null, dateTime);
                    }
                }

                void RandomWithdraw()
                {
                    for (int i = 0; i < numOfTransactions; i++)
                    {
                        accountAdapter.WithdrawWithSpecTime(random.Next(20, 500), dateTime);
                    }
                }

                void RandomTransfer()
                {
                    for (int i = 0; i < numOfTransactions; i++)
                    {
                        try
                        {
                            AccountTransferAdapter accTransferAdapter =
                                new AccountTransferAdapter(acc, accounts[random.Next(0, accounts.Count)]);
                            accTransferAdapter.TransferTransactionWithSpecTime(random.Next(10, 800), null, dateTime);
                            accTransferAdapter.ExecuteTransferTransaction();
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
            }
        }