Beispiel #1
0
        public IInterestAccount OpenInterestAccount(InterestAccountType type, decimal initialDeposit, InterestCounpoundType compoundType = InterestCounpoundType.Daily, double defaultRate = 0.0)
        {
            ValidationHelper.NotNull(type, "type");
            ValidationHelper.NegativeNumeric <decimal>(initialDeposit, "initialDeposit");
            ValidationHelper.NegativeNumeric <double>(defaultRate, "defaultRate");

            IInterestAccount _account = null;

            switch (type)
            {
            case (InterestAccountType.Checking):
                _account = new CheckingAccount(initialDeposit, compoundType, defaultRate);
                break;

            case (InterestAccountType.Savings):
                _account = new SavingsAccount(initialDeposit, compoundType, defaultRate);
                break;

            case (InterestAccountType.MaxiSavings):
                _account = new MaxiSavingsAccount(initialDeposit, compoundType, defaultRate);
                break;

            default:
                throw new Exception("Account type is not yet supported");
            }

            this.InterestAccounts.Add(_account);
            return(_account);
        }
 public void Transfer(IInterestAccount receivingAccount, decimal amount, DateTime date)
 {
     ValidationHelper.NotNull(receivingAccount, "receivingAccount");
     ValidationHelper.NegativeTransactionValue(amount, "amount");
     ValidationHelper.ZeroTransactionValue(amount, "amount");
     this.Transactions.Add(new Transaction(amount * -1, TransactionType.TransferOut, date));
     receivingAccount.Transactions.Add(new Transaction(amount, TransactionType.TransferIn, date));
 }
Beispiel #3
0
 public void TestInit()
 {
     // Initial deposit of $100
     // Do not override the default rates
     // Compound type is daily
     _SavingsAccount     = new SavingsAccount(1000);
     _CheckingAccount    = new CheckingAccount(1000);
     _MaxiSavingsAccount = new MaxiSavingsAccount(1000);
 }
Beispiel #4
0
        public void Accounts_AreInterestsAccruing()
        {
            IInterestAccount _SavingsAccount;
            IInterestAccount _CheckingAccount;
            IInterestAccount _MaxiSavingsAccount;

            // Initial deposit of $100
            // Do not override the default rates
            // Compound type is daily
            _SavingsAccount     = new SavingsAccount(1000);
            _CheckingAccount    = new CheckingAccount(1000);
            _MaxiSavingsAccount = new MaxiSavingsAccount(1000);

            _SavingsAccount.Deposit(2000);                    //Tr 2
            _SavingsAccount.Withdraw(1500);                   // Tr 3
            _SavingsAccount.Deposit(10000);                   // Tr 4
            _SavingsAccount.Transfer(_CheckingAccount, 4000); // Tr 5

            DateTime _futDate_4 = DateProvider.Now().AddDays(4);
            DateTime _futDate_7 = DateProvider.Now().AddDays(7);


            // No transactions prior to the periods
            decimal _fut4_interest;
            decimal _fut7_interest;

            _fut4_interest = _SavingsAccount.InterestEarned(_futDate_4);
            _fut7_interest = _SavingsAccount.InterestEarned(_futDate_7);


            Debug.Print(_fut4_interest.ToString());

            Assert.AreEqual("$0.16", _fut4_interest.ToDollars());
            Assert.AreEqual("$0.29", _fut7_interest.ToDollars());

            // Test again when there is transaction in duration


            DateTime _futDate_8  = DateProvider.Now().AddDays(8);
            DateTime _futDate_9  = DateProvider.Now().AddDays(9);
            DateTime _futDate_11 = DateProvider.Now().AddDays(11);

            _SavingsAccount.Deposit(5000, _futDate_8);
            _SavingsAccount.Withdraw(7000, _futDate_9);

            _fut7_interest = _SavingsAccount.InterestEarned(_futDate_11);
            Assert.AreEqual("$0.46", _fut7_interest.ToDollars());
        }
Beispiel #5
0
 public void OpenInterestAccount(IInterestAccount account)
 {
     ValidationHelper.NotNull(account, "account");
     this.InterestAccounts.Add(account);
 }
 public void Transfer(IInterestAccount receivingAccount, decimal amount)
 {
     this.Transfer(receivingAccount, amount, DateProvider.Now());
 }