[Test] //Test customer statement generation
        public void TestRenderCustomerStatement()
        {

            TextCustomerRenderer renderer=new TextCustomerRenderer();
            IAccountFactory accountFactory=new AccountFactory(DateProvider.getInstance());
            Account checkingAccount = accountFactory.CreateAccount(AccountType.CHECKING);
            Account savingsAccount = accountFactory.CreateAccount(AccountType.SAVINGS);

            Customer henry = new Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount);

            checkingAccount.deposit(100.0);
            savingsAccount.deposit(4000.0);
            savingsAccount.withdraw(200.0);

            Assert.AreEqual("Statement for Henry\n" +
                    "\n" +
                    "Checking Account\n" +
                    "  deposit $100.00\n" +
                    "Total $100.00\n" +
                    "\n" +
                    "Savings Account\n" +
                    "  deposit $4,000.00\n" +
                    "  withdrawal $200.00\n" +
                    "Total $3,800.00\n" +
                    "\n" +
                    "Total In All Accounts $3,900.00", renderer.Render(henry));
        }
示例#2
0
        [Test] //Test customer statement generation
        public void TestRenderCustomerStatement()
        {
            TextCustomerRenderer renderer       = new TextCustomerRenderer();
            IAccountFactory      accountFactory = new AccountFactory(DateProvider.getInstance());
            Account checkingAccount             = accountFactory.CreateAccount(AccountType.CHECKING);
            Account savingsAccount = accountFactory.CreateAccount(AccountType.SAVINGS);

            Customer henry = new Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount);

            checkingAccount.deposit(100.0);
            savingsAccount.deposit(4000.0);
            savingsAccount.withdraw(200.0);

            Assert.AreEqual("Statement for Henry\n" +
                            "\n" +
                            "Checking Account\n" +
                            "  deposit $100.00\n" +
                            "Total $100.00\n" +
                            "\n" +
                            "Savings Account\n" +
                            "  deposit $4,000.00\n" +
                            "  withdrawal $200.00\n" +
                            "Total $3,800.00\n" +
                            "\n" +
                            "Total In All Accounts $3,900.00", renderer.Render(henry));
        }
示例#3
0
        public void Account_Factory_Create_Account_Test()
        {
            var accFactory = new AccountFactory();
            var acc        = accFactory.CreateAccount(1, 3000);

            Assert.Equal(3000, acc.Balance);
        }
 static void Main(string[] args)
 {
     try {
         Account acc1 = AccountFactory.CreateAccount(100);
         Console.WriteLine("acc1= " + acc1.Balance);
         acc1.Deposit(10);
         Console.WriteLine("acc1= " + acc1.Balance);
         acc1.Withdraw(20);
         Console.WriteLine("acc1= " + acc1.Balance);
         Account acc2 = AccountFactory.CreateAccount(130);
         Console.WriteLine("acc2= " + acc2.Balance);
         acc2.Transfer(acc1, -50);
         Console.WriteLine("acc2 after transfer from acc2 " + acc1.Balance);
         Console.WriteLine("acc1 after transfring from acc2" + acc2.Balance);
         Console.WriteLine(acc1.ID);
         Console.WriteLine(acc2.ID);
     }
     catch (ArgumentOutOfRangeException e)
     {
         Console.WriteLine(e.Message);
     }
     catch (InsufficientFundsException e)
     {
         Console.WriteLine(e.Message);
     }
 }
示例#5
0
        static void Main(string[] args)
        {
            try
            {
                Account acc1 = AccountFactory.CreateAccount(1500);
                Account acc2 = AccountFactory.CreateAccount(0);

                try
                {
                    Account acc3 = AccountFactory.CreateAccount(-500);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Did Not creat an account with a negative balance");
                }

                try
                {
                    acc2.Withdraw(700000);
                }
                catch (InsufficientFundsException e)
                {
                    Console.WriteLine("Cannot withdraw " + e.Amount + " dollars much from account " + e.AccID);
                    Console.WriteLine("Account " + e.AccID + " has InsufficientFunds.");
                }

                acc1.Transfer(acc2, 750);
                acc1.Transfer(acc2, -100);
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("You tried to deposit/withdraw a negative amount of cash");
            }
        }
        /// <summary>
        /// news a account
        /// </summary>
        /// <param name="accountDTO"></param>
        /// <returns></returns>
        public AccountDTO AddNewAccount(AccountDTO accountDTO)
        {
            //check preconditions
            if (accountDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddCustomerWithEmptyInformation);
            }

            var user = _accountRepository.Get(accountDTO.Mobile);

            if (user == null)
            {
                //Create the entity and the required associated data
                var gooder = new GooderAuthInfo(accountDTO.GooderAuthInfo_RealName, accountDTO.GooderAuthInfo_CardNo, accountDTO.GooderAuthInfo_CardNoUrl, accountDTO.GooderAuthInfo_HeadUrl, accountDTO.GooderAuthInfo_ComparyName, accountDTO.GooderAuthInfo_ComparyCity, accountDTO.GooderAuthInfo_ComparyAddress, accountDTO.GooderAuthInfo_BusinesslicenseUrl);

                var driver = new DriverAuthInfo(accountDTO.DriverAuthInfo_RealName, accountDTO.DriverAuthInfo_CardNo, accountDTO.DriverAuthInfo_HeadUrl, accountDTO.DriverAuthInfo_CarType, accountDTO.DriverAuthInfo_CarLength, accountDTO.DriverAuthInfo_CarNo, accountDTO.DriverAuthInfo_CarHeight, accountDTO.DriverAuthInfo_CarBrand, accountDTO.DriverAuthInfo_CarYear, accountDTO.DriverAuthInfo_DriverLicenceUrl, accountDTO.DriverAuthInfo_CarVehicleUrl);

                var location = new Location(accountDTO.CarLocation_Lng, accountDTO.CarLocation_Lat, accountDTO.CarLocation_LocationUpdateTime);

                var account = AccountFactory.CreateAccount(accountDTO.Mobile, accountDTO.PassWord, (UserType)accountDTO.UserType, driver, gooder, location);

                //save entity
                SaveAccount(account);

                //return the data with id and assigned default values
                return(account.ProjectedAs <AccountDTO>());
            }
            else
            {
                return(null);
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            bool exitFlag = false;

            Account acc1 = AccountFactory.CreateAccount(100);
            Account acc2 = AccountFactory.CreateAccount(100);

            while (!exitFlag)
            {
                Console.WriteLine("Choose action:  1. Deposit.  2. Withdraw.  3. Transfer.  4. Check Balance.  5. Exit.");
                string action1 = Console.ReadLine();
                switch (action1)
                {
                case "1":
                {
                    Console.WriteLine("Specify amount to deposit:");
                    decimal money = decimal.Parse(Console.ReadLine());
                    acc1.Deposit(money);
                    break;
                }

                case "2":
                {
                    Console.WriteLine("Specify amount to Withdraw:");
                    decimal money = decimal.Parse(Console.ReadLine());
                    acc1.Withdraw(money);
                    break;
                }

                case "3":
                {
                    Console.WriteLine("Specify amount to transfer:");
                    decimal money = decimal.Parse(Console.ReadLine());
                    Console.WriteLine("Input target account for transfer:");
                    Console.ReadLine();
                    Account acc = acc2;
                    acc1.Transfer(acc, money);
                    break;
                }

                case "4":
                {
                    Console.WriteLine("You currently have ${0} in your account.", acc1.Balance);
                    break;
                }

                case "5":
                {
                    exitFlag = true;
                    break;
                }

                default:
                {
                    Console.WriteLine("Error: Invalid opperation. Please try again.");
                    break;
                }
                }
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            Account account1 = AccountFactory.CreateAccount(100);

            Console.WriteLine("Account 1 balance: " + account1.Balance);
            Console.WriteLine("1. Deposit\n2. Withdraw\n3. Balance");
            switch (Console.ReadLine())
            {
            case "1":
                Console.WriteLine("Amount? ");
                account1.Deposit(int.Parse(Console.ReadLine()));
                break;

            case "2":
                Console.WriteLine("Amount? ");
                account1.Withdraw(int.Parse(Console.ReadLine()));
                break;

            case "3":
                Console.WriteLine("Balance: " + account1.Balance);
                break;
            }

            Account account2 = AccountFactory.CreateAccount(100000);

            Console.WriteLine("Account 1 balance: " + account1.Balance);
            Console.WriteLine("Account 2 balance: " + account2.Balance);
            Console.WriteLine("How much to transfer?");
            account1.Transfer(account2, int.Parse(Console.ReadLine()));
            Console.WriteLine("Account 1 balance: " + account1.Balance);
            Console.WriteLine("Account 2 balance: " + account2.Balance);
        }
示例#9
0
        static void Main(string[] args)
        {
            Account newAcc = AccountFactory.CreateAccount(200);

            try
            {
                newAcc.Deposit(10);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine(newAcc.Balance);

            try
            {
                newAcc.Withdraw(230);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine(ex.Message);
            }


            Account newAcc2 = AccountFactory.CreateAccount(200);

            newAcc.Transfer(newAcc2, 10);
            Console.WriteLine(newAcc2.Balance);
        }
示例#10
0
        public void TestGenerateStatement()
        {
            IAccount checkingAccount    = AccountFactory.CreateAccount(AccountFactory.CHECKING);
            IAccount savingsAccount     = AccountFactory.CreateAccount(AccountFactory.SAVINGS);
            IAccount maxisavingsAccount = AccountFactory.CreateAccount(AccountFactory.MAXI_SAVINGS);
            Customer henry = new Customer("Henry").OpenAccount(checkingAccount).OpenAccount(savingsAccount).OpenAccount(maxisavingsAccount);

            checkingAccount.Deposit(100.0);
            savingsAccount.Deposit(4000.0);
            savingsAccount.Withdraw(200.0);
            maxisavingsAccount.Deposit(200.0);
            Assert.AreEqual("Statement for Henry\n" +
                            "\n" +
                            "Checking Account\n" +
                            "  deposit $100.00\n" +
                            "Total $100.00\n" +
                            "\n" +
                            "Savings Account\n" +
                            "  deposit $4,000.00\n" +
                            "  withdrawal $200.00\n" +
                            "Total $3,800.00\n" +
                            "\n" +
                            "Maxi Savings Account\n" +
                            "  deposit $200.00\n" +
                            "Total $200.00\n" +
                            "\n" +
                            "Total In All Accounts $4,100.00", henry.GetStatement());
        }
 public void TestCreateCheckingAccount()
 {
     AccountFactory factory = new AccountFactory(DateProvider.getInstance());
     Account account =  factory.CreateAccount(AccountType.CHECKING);
     Assert.IsNotNull(account);
     Assert.AreEqual(AccountType.CHECKING, account.AccountType);
 }
        public async Task <IActionResult> Create([Bind(properties)] AccountView c)
        {
            c.ID = BankId.NewBankId();
            await validateId(c.ID, ModelState);

            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            c.Balance = 500;
            c.Status  = Status.Active.ToString();
            //c.Type = Enum.GetName(typeof(CardType), int.Parse(c.Type));
            var loggedInUser = await userManager.GetUserAsync(HttpContext.User);

            c.AspNetUserId = loggedInUser.Id;
            var o = AccountFactory.CreateAccount(c.ID, c.Balance, c.Type, c.Status, c.AspNetUserId,
                                                 c.ValidFrom = DateTime.Now, c.ValidTo = DateTime.Now.AddYears(2));
            await repository.AddObject(o);

            await _bankHub.Clients.All.SendAsync("NewAccount", c.ID, c.Type, c.Balance, c.Status, c.ValidTo.Value.Date.ToShortDateString());

            await createWelcomeNotification(c.ID);
            await createWelcomeTransaction(c.ID);

            return(RedirectToAction("Index", "Home"));
        }
示例#13
0
        public void TestCreateMaxiSavingsAccount()
        {
            IAccount maxiSavingsAccount = AccountFactory.CreateAccount(AccountFactory.MAXI_SAVINGS);
            Customer henry = new Customer("Henry").OpenAccount(maxiSavingsAccount);

            Assert.AreEqual(1, henry.GetNumberOfAccounts());
        }
示例#14
0
        static void Main(string[] args)
        {
            Account account1 = AccountFactory.CreateAccount(100);
            Account account2 = AccountFactory.CreateAccount(100000);

            Console.WriteLine("Account 1 balance: " + account1.Balance);
            Console.WriteLine("Account 2 balance: " + account2.Balance);
            Console.WriteLine("How much to transfer?");
            try
            {
                long amount;

                if (long.TryParse(Console.ReadLine(), out amount))
                {
                    account1.Transfer(account2, amount);
                    Console.WriteLine("Account 1 balance: " + account1.Balance);
                    Console.WriteLine("Account 2 balance: " + account2.Balance);
                }
                else
                {
                    Console.WriteLine("Invalid Input.");
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public void TestCreateMaxiSavingAccount()
        {
            AccountFactory factory = new AccountFactory(DateProvider.getInstance());
            Account account = factory.CreateAccount(AccountType.MAXI_SAVINGS);
            Assert.IsNotNull(account);
            Assert.AreEqual(AccountType.MAXI_SAVINGS, account.AccountType);

        }
示例#16
0
        public void TestDepositToSavingsAccount()
        {
            IAccount savingsAccount = AccountFactory.CreateAccount(AccountFactory.SAVINGS);
            Customer henry          = new Customer("Henry").OpenAccount(savingsAccount);

            savingsAccount.Deposit(1500.0);
            Assert.AreEqual(1500, savingsAccount.GetCurrentBalance());
        }
        public void TestCreateMaxiSavingAccount()
        {
            AccountFactory factory = new AccountFactory(DateProvider.getInstance());
            Account        account = factory.CreateAccount(AccountType.MAXI_SAVINGS);

            Assert.IsNotNull(account);
            Assert.AreEqual(AccountType.MAXI_SAVINGS, account.AccountType);
        }
示例#18
0
        public Account CreateAccount(CreateAccountCommand command)
        {
            Account account = AccountFactory.CreateAccount(command.AccountType);

            account.InitializePositions();

            return(account);
        }
示例#19
0
        public void TestTwoAccount()
        {
            Customer oscar = new Customer("Oscar")
                             .OpenAccount(AccountFactory.CreateAccount(AccountFactory.SAVINGS));

            oscar.OpenAccount(AccountFactory.CreateAccount(AccountFactory.CHECKING));
            Assert.AreEqual(2, oscar.GetNumberOfAccounts());
        }
        public void TestCreateCheckingAccount()
        {
            AccountFactory factory = new AccountFactory(DateProvider.getInstance());
            Account        account = factory.CreateAccount(AccountType.CHECKING);

            Assert.IsNotNull(account);
            Assert.AreEqual(AccountType.CHECKING, account.AccountType);
        }
示例#21
0
        public void CustomerSummary()
        {
            Bank     bank = new Bank();
            Customer john = new Customer("John");

            john.OpenAccount(AccountFactory.CreateAccount(AccountFactory.CHECKING));
            bank.AddCustomer(john);
            Assert.AreEqual("Customer Summary\n - John (1 account)", bank.CustomerSummary());
        }
示例#22
0
        public void TestWithDrawAmountinCheckingAccount()
        {
            IAccount checkingAccount = AccountFactory.CreateAccount(AccountFactory.CHECKING);
            Customer henry           = new Customer("Henry").OpenAccount(checkingAccount);

            checkingAccount.Deposit(1500.0);
            checkingAccount.Withdraw(500.0);
            Assert.AreEqual(1000, checkingAccount.GetCurrentBalance());
        }
示例#23
0
        public static void CreateAccount_ShouldReturnAccountOfSameType(AccountType accountType)
        {
            const string id             = "1234";
            var          accountFactory = new AccountFactory();
            var          expected       = accountType;

            var actual = accountFactory.CreateAccount(accountType, id).AccountType;

            Assert.Equal(expected, actual);
        }
示例#24
0
        public void TestTransferAmountSendingInvalidAccountId()
        {
            IAccount checkingAccount = AccountFactory.CreateAccount(AccountFactory.CHECKING);
            IAccount savingsAccount  = AccountFactory.CreateAccount(AccountFactory.SAVINGS);
            Customer oscar           = new Customer("Oscar").OpenAccount(checkingAccount).OpenAccount(savingsAccount);

            checkingAccount.Deposit(1500.0);
            savingsAccount.Deposit(1500.0);
            oscar.TransferAmount(500, "18", savingsAccount.Id);
        }
示例#25
0
        public void GetAllTransactionsOfMaxiSavingsAccount()
        {
            IAccount maxiSavingsAccount = AccountFactory.CreateAccount(AccountFactory.MAXI_SAVINGS);
            Customer henry = new Customer("Henry").OpenAccount(maxiSavingsAccount);

            maxiSavingsAccount.Deposit(1500.0);
            maxiSavingsAccount.Withdraw(500.0);
            maxiSavingsAccount.Deposit(500.0);
            Assert.AreEqual(3, maxiSavingsAccount.GetAllTransactions().Count);
        }
示例#26
0
        public void CheckTransactionFieldsAreCorrect()
        {
            IAccount savingsAccount = AccountFactory.CreateAccount(AccountFactory.SAVINGS);
            Customer henry          = new Customer("Henry").OpenAccount(savingsAccount);

            savingsAccount.Deposit(1500.0);
            Transaction trans = new Transaction(1500, 0, TransactionType.Deposit);

            Assert.IsTrue(savingsAccount.GetAllTransactions().Exists(p => (p.Balance == 1500 && p.TransactionAmount == 1500 && (string.Compare(p.TransactionType.ToString(), TransactionType.Deposit.ToString()) == 0))));
        }
        public void CreateAccountSetsBalanceToZero()
        {
            // Arrange
            IAccount testAccount = AccountFactory.CreateAccount(AccountType.Silver);
            // Act
            decimal balance = testAccount.Balance;

            // Assert
            Assert.AreEqual(balance, 0.00M);
        }
        public void NullAccountReturned()
        {
            // Arrange
            AccountService acctService = new AccountService();
            // Act
            string   accountName = "Test Null";
            IAccount newAccount  = AccountFactory.CreateAccount(AccountType.Null);

            //Assert
            Assert.AreEqual(acctService.FindAccount(accountName), newAccount);
        }
示例#29
0
        public static Account ToAccount(this AccountDTO accountDTO)
        {
            AccountFactory factory = FactoryCollection.Factories.FirstOrDefault(f => (int)f.AccountType == accountDTO.AccountTypeId);
            Account        account = factory.CreateAccount(accountDTO.Number, accountDTO.Owner.ToOwner(), accountDTO.Balance);

            account.Id          = accountDTO.Id;
            account.BonusPoints = accountDTO.BonusPoints;
            account.IsOponed    = accountDTO.IsOponed;

            return(account);
        }
        public void TestRenderCustomerSummary()
        {
            TextBankRenderer renderer=new TextBankRenderer();
            Bank bank = new Bank();
            Customer john = new Customer("John");
            IAccountFactory accountFactory = new AccountFactory(DateProvider.getInstance());
            john.openAccount(accountFactory.CreateAccount(AccountType.CHECKING));
            bank.addCustomer(john);

            Assert.AreEqual("Customer Summary\n - John (1 account)", renderer.Render(bank));
        }
        private Account CreateAccountCore(AccountFactory accountCreator, Owner owner, decimal initialBalance)
        {
            string accountNumber = ReciveAccountNumber();

            Account account = accountCreator.CreateAccount(accountNumber, owner, initialBalance);

            accountRepository.Add(account.ToAccountDTO());

            unitOfWork.Commit();

            return(account);
        }
        public void DepositToAccountBalance()
        {
            // Arrange
            IAccount testAccount = AccountFactory.CreateAccount(AccountType.Silver);

            // Act
            testAccount.AddTransaction(+123.45M);
            decimal balance = testAccount.Balance;

            // Assert
            Assert.AreEqual(balance, +123.45M);
        }
示例#33
0
        public void TestRenderCustomerSummary()
        {
            TextBankRenderer renderer       = new TextBankRenderer();
            Bank             bank           = new Bank();
            Customer         john           = new Customer("John");
            IAccountFactory  accountFactory = new AccountFactory(DateProvider.getInstance());

            john.openAccount(accountFactory.CreateAccount(AccountType.CHECKING));
            bank.addCustomer(john);

            Assert.AreEqual("Customer Summary\n - John (1 account)", renderer.Render(bank));
        }
示例#34
0
        public void TestTransferAmountInsufficientFundsFail()
        {
            IAccount checkingAccount    = AccountFactory.CreateAccount(AccountFactory.CHECKING);
            IAccount savingsAccount     = AccountFactory.CreateAccount(AccountFactory.SAVINGS);
            IAccount maxiSavingsAccount = AccountFactory.CreateAccount(AccountFactory.MAXI_SAVINGS);
            Customer oscar = new Customer("Oscar").OpenAccount(checkingAccount).OpenAccount(savingsAccount).OpenAccount(maxiSavingsAccount);

            checkingAccount.Deposit(1500.0);
            savingsAccount.Deposit(1500.0);
            maxiSavingsAccount.Deposit(1500.0);
            oscar.TransferAmount(2000, checkingAccount.Id, savingsAccount.Id);
        }