コード例 #1
0
/// <remarks>
/// This function adds n Account for a Customer and sets the intial balance and over draft limit.
/// </remarks>
/// <param name="customerId">A interger customerId.</param>
/// <param name="accountType">A string containing accountType.</param>
/// <param name="balance">A float amount for the initial balance.</param>
/// <param name="overdraft">A float amount for the initial overdraft limit amount.</param>
        public void AddAccount(int customerId, string accountType, float balance, float overdraft)
        {
            CustomerList = Customer.CustomerList;
            Customer customer = FindCustomerById(customerId);
            int      i        = 1;

            if (accountType == "Everyday")
            {
                foreach (EverydayAccount e in customer.EverydayAccount)
                {
                    if (e.AccountId == i)
                    {
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
                EverydayAccount everyday = new EverydayAccount(customer, i, balance);
                customer.EverydayAccount.Add(everyday);
                Customer.CustomerList = CustomerList;
            }
            else if (accountType == "Investment")
            {
                foreach (InvestmentAccount e in customer.InvestmentAccount)
                {
                    if (e.AccountId == i)
                    {
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
                InvestmentAccount investment = new InvestmentAccount(customer, i, balance);
                customer.InvestmentAccount.Add(investment);
                Customer.CustomerList = CustomerList;
            }
            else if (accountType == "Omni")
            {
                foreach (OmniAccount e in customer.OmniAccount)
                {
                    if (e.AccountId == i)
                    {
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
                OmniAccount omni = new OmniAccount(customer, i, balance, overdraft);
                customer.OmniAccount.Add(omni);
                Customer.CustomerList = CustomerList;
            }
            SerializeNow();
        }
コード例 #2
0
        //tests the calaculate invest function
        public void CalculateInterestOmni()
        {
            float initialBalance = 200;
            float expected       = 210;

            Customer    customer    = new Customer(4, "Allen", "02222222");
            OmniAccount omniAccount = new OmniAccount(customer, 5, initialBalance, 5, 20, 1000);

            float actual = omniAccount.CalculateInterest();

            Assert.AreEqual(expected, actual, 0.001);
        }
コード例 #3
0
        public void WithdrawWithValidAmountOmni()
        {
            float initialBalance = 200;
            float withdrawAmount = 50;
            float expected       = 150;

            Customer    customer    = new Customer(4, "Allen", "02222222");
            OmniAccount omniAccount = new OmniAccount(customer, 5, initialBalance, 5, 20, 1000);

            float actual = omniAccount.Withdraw(withdrawAmount);

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        public void DepositWithValidAmountOmni()
        {
            float initialBalance = 200;
            float depositAmount  = 50;
            float expected       = 250;

            Customer    customer    = new Customer(4, "Allen", "02222222");
            OmniAccount omniAccount = new OmniAccount(customer, 5, initialBalance, 5, 20, 1000);

            float actual = omniAccount.Deposit(depositAmount);

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void WithdrawWithLessThanZeroOmni()
        {
            float initialBalance = 200;
            float withdrawAmount = -10;

            Customer    customer    = new Customer(4, "Allen", "02222222");
            OmniAccount omniAccount = new OmniAccount(customer, 5, initialBalance, 5, 20, 1000);

            try
            {
                omniAccount.Withdraw(withdrawAmount);
            }
            catch (ArgumentOutOfRangeException)
            {
                return;
            }
            Assert.Fail();
        }
コード例 #6
0
        public void DepositWithInvalidAmountOmni()
        {
            float initialBalance = 200;
            float depositAmount  = -50;

            Customer    customer    = new Customer(4, "Allen", "02222222");
            OmniAccount omniAccount = new OmniAccount(customer, 5, initialBalance, 5, 20, 1000);

            try
            {
                omniAccount.Deposit(depositAmount);
            }
            catch (ArgumentOutOfRangeException)
            {
                return;
            }
            Assert.Fail();
        }