Exemple #1
0
        public void CalculateInterest_AccrualhMode_Daily_EndOfYear_OneClosure_AfterOneWeek_Agio()
        {
            Assert.Ignore();
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);
            _bookProduct.InterestFrequency = OSavingInterestFrequency.EndOfYear;
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(),
                new DateTime(2009, 01, 01), null) { Product = _bookProduct, InterestRate = 0.1, AgioFees = 0.1 };

            saving.Closure(new DateTime(2009, 01, 08), new User() { Id = 1 });

            int accrualEvents = saving.Events.FindAll(item => item is SavingInterestsAccrualEvent).Count;
            int postingEvents = saving.Events.FindAll(items => items is SavingInterestsPostingEvent).Count;

            List<SavingEvent> agioEvents = saving.Events.FindAll(items => items is SavingAgioEvent);
            Assert.AreEqual(agioEvents.Count, 7);
            Assert.AreEqual(agioEvents[0].Fee, 10);
            Assert.AreEqual(saving.GetBalance(), -170);

            //            saving.Deposit(200, new DateTime(2009, 01, 08), "depot", new User(), false, false, OPaymentMethods.Cash, null, null);
            saving.Deposit(200, new DateTime(2009, 01, 08), "depot", new User(), false, false, OSavingsMethods.Cash, null, null);
            //saving.Withdraw(230, new DateTime(2009, 02, 03), "retrait", new User(), false);

            saving.Closure(new DateTime(2009, 01, 15), new User() { Id = 1 });
            List<SavingEvent> agioEvents2 = saving.Events.FindAll(items => items is SavingAgioEvent);
            Assert.AreEqual(agioEvents2.Count, 13);
            Assert.AreEqual(agioEvents2[9].Fee, 13);
            Assert.AreEqual(saving.GetBalance(), -51);
        }
Exemple #2
0
        public void CalculateInterest_AccrualhMode_Daily_EndOfYear_OneClosure_AfterOneWeek()
        {
            ApplicationSettings.GetInstance("").UpdateParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Accrual);
            _product.InterestFrequency = OSavingInterestFrequency.EndOfYear;
            SavingBookContract saving =
                new SavingBookContract(
                    ApplicationSettings.GetInstance(""),
                     new User(),
                    new DateTime(2009, 01, 01),
                    null)
                    {
                        Product = _product,
                        InterestRate = 0.1,
                        AgioFees = 8
                    };
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            saving.Closure(new DateTime(2009, 01, 08), new User() { Id = 1 });

            int accrualEvents = saving.Events.FindAll(item => item is SavingInterestsAccrualEvent).Count;
            int postingEvents = saving.Events.FindAll(items => items is SavingInterestsPostingEvent).Count;

            Assert.AreEqual(7, accrualEvents);
            Assert.AreEqual(0, postingEvents);
            Assert.AreEqual(1000m, saving.GetBalance().Value);
        }
Exemple #3
0
        public void PostingInterests_OnePosting()
        {
            SavingsBookProduct product = new SavingsBookProduct
                                            {
                                                Id = 1,
                                                InterestBase = OSavingInterestBase.Daily,
                                                InterestFrequency = OSavingInterestFrequency.EndOfDay,
                                                Periodicity = new InstallmentType("Daily", 1, 0)
                                            };
            SavingBookContract saving = new SavingBookContract(
                ApplicationSettings.GetInstance(""),
                new User(),
                new DateTime(2009, 01, 01), null)
                                            {
                                                Product = product,
                                                InterestRate = 0.1
                                            };
            saving.NextMaturity = saving.CreationDate;
            List<SavingInterestsPostingEvent> list = new List<SavingInterestsPostingEvent>();
            list = saving.PostingInterests(
                                            saving.NextMaturity.Value,
                                            new User { Id = 1 }
                                            );

            Assert.AreEqual(1, list.Count);
        }
Exemple #4
0
        public void PostingInterests_NoPosting()
        {
            //            Assert.Ignore();
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id = 1,
                InterestBase = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfYear,
                Periodicity = new InstallmentType("Yearly", 0, 12)

            };
            SavingBookContract saving = new SavingBookContract(
                                                        ApplicationSettings.GetInstance(""),
                                                        new User(),
                                                        new DateTime(2009, 01, 01),
                                                        null)
                                            {
                                                Product = product,
                                                InterestRate = 0.1,
                                                NextMaturity = new DateTime(2009, 01, 01)
                                            };
            List<SavingInterestsPostingEvent> list = new List<SavingInterestsPostingEvent>();
            list = saving.PostingInterests(new DateTime(2009, 02, 01), new User { Id = 1 });

            Assert.AreEqual(list.Count, 0);
        }
        public override object Clone()
        {
            SavingBookContract saving = (SavingBookContract)MemberwiseClone();

            saving.Events = new List <SavingEvent>();
            saving.Events.AddRange(Events);
            return(saving);
        }
Exemple #6
0
        public void PostingInterests_12Posting()
        {
            //            Assert.Ignore();
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id = 1,
                InterestBase = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfMonth,
                Periodicity = new InstallmentType("Monthly", 0, 1)

            };

            User user = new User() {Id = 1};
            DateTime creationDate = new DateTime(2009, 01, 01);
            SavingBookContract saving = new SavingBookContract(
                                                                    ApplicationSettings.GetInstance(""),
                                                                    user,
                                                                    creationDate,
                                                                    null
                                                                )
                                                            {
                                                                Product = product,
                                                                InterestRate = 0.1
                                                            };
            DateTime closureDate = new DateTime(2010, 01, 01);
            saving.NextMaturity = saving.CreationDate.Date;
            saving.NumberOfPeriods = 1;
            saving.FirstDeposit(1000, creationDate, 0, user, new Teller());
            saving.NextMaturity = DateCalculationStrategy.GetNextMaturity(
                                                                        saving.CreationDate.Date,
                                                                        saving.Product.Periodicity,
                                                                        saving.NumberOfPeriods);
            List<SavingInterestsAccrualEvent> interestsAccrualEvents =
                                    saving.CalculateInterest(closureDate, new User {Id = 1});
            foreach (var accrualEvent in interestsAccrualEvents)
            {
                saving.Events.Add(accrualEvent);
            }
            List<SavingInterestsPostingEvent> list = new List<SavingInterestsPostingEvent>();
            List<SavingInterestsPostingEvent> postingEvents = new List<SavingInterestsPostingEvent>();

            while (saving.NextMaturity.Value <= closureDate)
            {
                list = saving.PostingInterests(saving.NextMaturity.Value, new User() {Id = 1});
                postingEvents.AddRange(list);
                foreach (var postingEvent in list)
                {
                    saving.Events.Add(postingEvent);
                }
                saving.NextMaturity = DateCalculationStrategy.GetNextMaturity(saving.NextMaturity.Value, saving.Periodicity, 1);
            }

            list = saving.PostingInterests(new DateTime(2010, 01, 01), new User { Id = 1 });

            Assert.AreEqual(12, postingEvents.Count);
        }
Exemple #7
0
        public void CalculateInterest_NoDay()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id = 1,
                InterestBase = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfYear
            };
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(),
                new DateTime(2009, 07, 01), null) { Product = product, InterestRate = 0.1 };

            List<SavingInterestsAccrualEvent> list = new List<SavingInterestsAccrualEvent>();
            list = saving.CalculateInterest(new DateTime(2009, 07, 01), new User { Id = 1 });

            Assert.AreEqual(list.Count, 0);
        }
        public void Init(IClient client, Loan loan, Guarantee guarantee, SavingBookContract savings, IList<IPrintButtonContextMenuStrip> printMenus)
        {
            _printButton.AttachmentPoint = AttachmentPoint.CreditCommittee;
            Visibility visibility;
            switch (client.Type)
            {
                case OClientTypes.Person:
                    visibility = Visibility.Individual;
                    break;

                case OClientTypes.Group:
                    visibility = Visibility.Group;
                    break;

                case OClientTypes.Corporate:
                    visibility = Visibility.Corporate;
                    break;

                default:
                    visibility = Visibility.All;
                    break;
            }
            _printButton.Visibility = visibility;

            _printButton.ReportInitializer =
                report =>
                {
                    report.SetParamValue("user_id", User.CurrentUser.Id);
                    if (loan != null) report.SetParamValue("contract_id", loan.Id);
                };
            _printButton.LoadReports();

            foreach (var item in printMenus)
            {
                var menuItems = item.GetContextMenuStrip(client, loan, guarantee, savings, AttachmentPoint.CreditCommittee.ToString());
                if (menuItems == null) continue;

                foreach (var menuItem in menuItems)
                {
                    _printButton.Menu.Items.Add(menuItem);
                }
            }
        }
        public void AddSavingBook()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                new User() { Id = 1 }, new DateTime(2009, 01, 01), _savingsBookProduct, null)
            {
                Code = "S/CR/2009/SAVIN-1/BAR-1", Status = OSavingsStatus.Active, InterestRate = 0.01, FlatWithdrawFees = 3, FlatTransferFees = 3
            };
            saving.InitialAmount = 1000;
            saving.EntryFees = 10;
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            User user = new User {Id = 1};
            saving.Events[0].User = user;
            saving.Events[0].Id = 400;
            saving.SavingsOfficer = user;
            saving.Id = _savingManager.Add(saving, new Person { Id = 6 });
            _savingEventManager.Add(saving.Events[0], saving.Id);

            SavingBookContract retrievedSaving = (SavingBookContract)_savingManager.Select(saving.Id);

            _compareSavings(saving, retrievedSaving);
        }
Exemple #10
0
        public void Create_Saving_Book_Account_With_EntryFees()
        {
            SavingsBookProduct product = new SavingsBookProduct()
            {
                Name = "NewSavingProduct",
                InitialAmountMin = 1000,
                InitialAmountMax = 2000,
                DepositMin = 100,
                DepositMax = 200,
                WithdrawingMin = 100,
                WithdrawingMax = 200,
                InterestRate = 0.2,
                BalanceMin = 1000,
                BalanceMax = 2000,
                InterestBase = OSavingInterestBase.Monthly,
                InterestFrequency = OSavingInterestFrequency.EndOfYear,
                CalculAmountBase = OSavingCalculAmountBase.MinimalAmount,
                ClientType = OClientTypes.All,
                EntryFeesMin = 5,
                EntryFeesMax = 15,
                Currency = new Currency { Id = 1 }
            };

            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(),
                new DateTime(2009, 01, 01), product, null);
            saving.InitialAmount = 1000;
            saving.EntryFees = 10;
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), 10, new User(), Teller.CurrentTeller);

            Assert.AreEqual(saving.GetBalance(), 1000);
            Assert.AreEqual(saving.Events.Count, 1);
            Assert.AreEqual(saving.InitialAmount, 1000);
            Assert.AreEqual(saving.EntryFees, 10);
        }
Exemple #11
0
        public void Charge_reopen_fees()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                                       new User(), new DateTime(2009, 1, 1), null)
            {
                Product = _bookProduct,
                AgioFees = 0.01,
                ChequeDepositFees = 100,
                DepositFees = 50,
                CloseFees = 100,
                ReopenFees = 100,
                OverdraftFees = 100
            };

            saving.Close(new DateTime(2009, 1, 2), new User(), "closing", false, Teller.CurrentTeller, false);
            List<SavingEvent> reopenEvents = saving.Reopen(100, new DateTime(2009, 1, 3), new User(), "reopen", false);

            foreach (SavingEvent reopenEvent in reopenEvents)
            {
                Assert.AreEqual(saving.ReopenFees, reopenEvent.Fee);
            }
        }
Exemple #12
0
        public void Charge_deposit_fees()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                                       new User(), new DateTime(2009, 1, 1), null)
            {
                Product = _bookProduct,
                AgioFees = 0.01,
                ChequeDepositFees = 100,
                DepositFees = 50,
                CloseFees = 100,
                ReopenFees = 100,
                OverdraftFees = 100
            };
            Currency currency = new Currency() { UseCents = true, Code = "SOM", Id = 1, IsPivot = true, Name = "SOM" };

            //            List<SavingEvent> cashDepositEvents = saving.Deposit(100, new DateTime(2009, 1, 2), "cash deposit", new User(), false,
            //                                                             false, OPaymentMethods.Cash, null, null);
            List<SavingEvent> cashDepositEvents = saving.Deposit(100, new DateTime(2009, 1, 2), "cash deposit", new User(), false,
                                                             false, OSavingsMethods.Cash, null, null);
            //            List<SavingEvent> chequeDepositEvents = saving.Deposit(100, new DateTime(2009, 1, 2), "cheque deposit", new User(), false,
            //                                                             false, OPaymentMethods.Cheque, null, null);
            List<SavingEvent> chequeDepositEvents = saving.Deposit(100, new DateTime(2009, 1, 2), "cheque deposit", new User(), false,
                                                             false, OSavingsMethods.Cheque, null, null);
            foreach (SavingEvent cashEvent in cashDepositEvents)
            {
                Assert.AreEqual(cashEvent.Fee, saving.DepositFees);
            }
            foreach (SavingEvent chequeEvent in chequeDepositEvents)
            {
                Assert.AreEqual(chequeEvent.Fee, saving.ChequeDepositFees);
            }
        }
Exemple #13
0
        public void Charge_close_reopen_fees()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                                       new User(), new DateTime(2009, 1, 1), null)
            {
                Product = _bookProduct,
                AgioFees = 0.01,
                ChequeDepositFees = 100,
                DepositFees = 50,
                CloseFees = 100,
                ReopenFees = 100,
                OverdraftFees = 100
            };
            Currency currency = new Currency() { UseCents = true, Code = "SOM", Id = 1, IsPivot = true, Name = "SOM" };

            List<SavingEvent> closeEvents = saving.Close(new DateTime(2009, 1, 2), new User(), "closing", false, Teller.CurrentTeller, false);

            Assert.AreEqual(OSavingsStatus.Closed, saving.Status);

            foreach (SavingEvent closeEvent in closeEvents)
            {
                Assert.AreEqual(closeEvent.Fee, saving.CloseFees);
            }
        }
Exemple #14
0
        public void TestSavingIsValid_TransferAmountIsInvalid()
        {
            Assert.Ignore();
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), TimeProvider.Today, null) { Id = 1, InterestRate = 0.13, Product = _savingsProduct };
            SavingBookContract savingTarget = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), TimeProvider.Today, null) { Id = 2, InterestRate = 0.13, Product = _savingsProduct };

            _savingManagerMock = new DynamicMock(typeof(SavingManager));
            _savingServices = new SavingServices((SavingManager)_savingManagerMock.MockInstance, null, new User { Id = 6 });

            _savingManagerMock.Expect("UpdateAccountsBalance", saving, null);
            _savingManagerMock.Expect("UpdateAccountsBalance", savingTarget, null);

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 99, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (transfer amount < transfer.min).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.TransferAmountIsInvalid, (int)exception.Code);
            }

            _savingManagerMock.Expect("UpdateAccountsBalance", saving, null);
            _savingManagerMock.Expect("UpdateAccountsBalance", savingTarget, null);

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 301, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (transfer amount > transfer.max).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.TransferAmountIsInvalid, (int)exception.Code);
            }

            _savingManagerMock.Expect("UpdateAccountsBalance", saving, null);
            _savingManagerMock.Expect("UpdateAccountsBalance", savingTarget, null);

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 200, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (balance < balance.min).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.BalanceIsInvalid, (int)exception.Code);
            }
        }
Exemple #15
0
        public void Charge_agio_fees()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                                       new User(), new DateTime(2009, 01, 01), null)
            {
                Product = _bookProduct,
                AgioFees = 0.01,
                ChequeDepositFees = 100,
                DepositFees = 50,
                CloseFees = 100,
                ReopenFees = 100,
                OverdraftFees = 100
            };
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            Currency currency = new Currency() { UseCents = true, Code = "SOM", Id = 1, IsPivot = true, Name = "SOM" };

            Assert.AreEqual(1000, saving.GetBalance().Value);

            //Below, we explicitly implement withdraw method from <Saving services>.<Withdraw>, since withdraw method of 'saving' object doesn't implement
            // overdraft fee by default

            List<SavingEvent> withdrawEvents = saving.Withdraw(1100, new DateTime(2009, 1, 2), "withdraw", new User(), false, null);
            saving.Closure(new DateTime(2009, 1, 12), new User());

            //agio for ten days
            Assert.AreEqual(-111.55, saving.GetBalance().Value);
        }
Exemple #16
0
 public void SeveralMgmtFeeEvents()
 {
     _saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), new DateTime(2007, 08, 11), _bookProduct, null);
     _saving.AgioFees = 0.1;
     _saving.ManagementFees = 50;
     _saving.FirstDeposit(10000, new DateTime(2007, 08, 01), null, new User(), Teller.CurrentTeller);
     _saving.Closure(new DateTime(2007, 12, 31), new User());
     List<SavingEvent> events = _saving.Events.FindAll(item => item is SavingManagementFeeEvent);
     Assert.AreEqual(events.Count, 4);
     Assert.AreEqual(9800,_saving.GetBalance().Value);
 }
Exemple #17
0
        public void TestSavingIsValid_InitialAmountTooSmall()
        {
            Assert.Ignore();
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), TimeProvider.Today, null)
            { InterestRate = 0.13, Product = _savingsProduct };

            _savingServices = new SavingServices(null, null, new User { Id = 6 });

            try
            {
                Client client = new Person { Id = 1 };
                _savingServices.SaveContract(saving, client);
                saving.FirstDeposit(1, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);
                Assert.Fail("Saving Contract shouldn't pass validation test before save (initial amount < product.min).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.EntryFeesIsInvalid, (int)exception.Code);
            }
        }
Exemple #18
0
        public void Test_SimulateCloseAccount()
        {
            Assert.Ignore();
            _savingServices = new SavingServices(null, null, new User { Id = 6 });

            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                new User { Id = 6 }, new DateTime(2009, 01, 01), _savingsProduct, null) { InterestRate = 0.15, ManagementFees = 0, AgioFees = 0 };
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            Assert.AreEqual(_savingServices.SimulateCloseAccount(saving, new DateTime(2009, 02, 15), new User(), false, Teller.CurrentTeller).GetBalance(), 5650);
        }
Exemple #19
0
        public void TestSaving_When_Product_IsNull()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), TimeProvider.Today, null)
            {
                InterestRate = 0.15
            };

            _savingServices = new SavingServices(null, null, new User { Id = 6 });

            try
            {
                _savingServices.SaveContract(saving, new Person { Id = 6 });
                Assert.Fail("Saving Contract shouldn't pass validation test before save (Product is Null).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual(exception.Code, OpenCbsSavingExceptionEnum.ProductIsInvalid);
            }
        }
Exemple #20
0
        public void TestSaving_When_InitialAmount_IsNull()
        {
            Assert.Ignore();
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                                                                new User())
                                            {
                                                CreationDate = TimeProvider.Today,
                                                InterestRate = 0.13,
                                                Product = _savingsProduct
                                            };

            _savingServices = new SavingServices(null, null, new User { Id = 6 });

            try
            {
                _savingServices.SaveContract(saving, new Person { Id = 6 });
                saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);
                Assert.Fail("Saving Contract shouldn't pass validation test before save (Initial Amount is Null).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual(exception.Code, OpenCbsSavingExceptionEnum.EntryFeesIsInvalid);
            }
        }
Exemple #21
0
        public void TestSaving_RateWithdrawFees()
        {
            Assert.Ignore();
            _savingsProduct.WithdrawFeesType = OSavingsFeesType.Rate;
            _savingsProduct.RateWithdrawFeesMin = 0.01;
            _savingsProduct.RateWithdrawFeesMax = 0.05;

            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User { Id = 6 },
                TimeProvider.Today, _savingsProduct, null) { InterestRate = 0.15, FlatTransferFees = 3, DepositFees = 5, CloseFees = 6,
                 ManagementFees = 7, AgioFees = 8 };
            Client client = new Person { Id = 6, LastName = "El Fanidi" };

            _savingManagerMock = new DynamicMock(typeof(SavingManager));
            _savingEventManagerMock = new DynamicMock(typeof(SavingEventManager));

            _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 1, 6);
            _savingManagerMock.ExpectAndReturn("Add", 1, saving, client, null);

            _savingServices = new SavingServices((SavingManager)_savingManagerMock.MockInstance, (SavingEventManager)_savingEventManagerMock.MockInstance, new User { Id = 6 });

            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code);
            }

            saving.RateWithdrawFees = 0;

            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code);
            }

            saving.RateWithdrawFees = 0.06;

            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code);
            }

            saving.RateWithdrawFees = 0.03;
            Assert.AreEqual(1, _savingServices.SaveContract(saving, client));

            saving.Product.RateWithdrawFees = 0.02;
            saving.Product.RateWithdrawFeesMin = null;
            saving.Product.RateWithdrawFeesMax = null;

            _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 2, 6);
            _savingManagerMock.ExpectAndReturn("Add", 2, saving, client, null);

            saving.RateWithdrawFees = null;

            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code);
            }

            saving.RateWithdrawFees = 0.01;

            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code);
            }

            saving.RateWithdrawFees = 0.03;

            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.WithdrawFeesIsInvalid, (int)exception.Code);
            }

            saving.RateWithdrawFees = 0.02;
            Assert.AreEqual(2, _savingServices.SaveContract(saving, client));
        }
Exemple #22
0
        public void TestSavingIsValid_TransferIsInvalid()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), TimeProvider.Today, null) { InterestRate = 0.13, Product = _savingsProduct };
            SavingBookContract savingTarget = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), TimeProvider.Today, null) { InterestRate = 0.13, Product = _savingsProduct, Status = OSavingsStatus.Closed };

            _savingServices = new SavingServices(null, null, new User { Id = 6 });

            try
            {
                _savingServices.Transfer(saving, saving, TimeProvider.Today, 99, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (Saving source = Saving Target).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.SavingsContractForTransferIdenticals, (int)exception.Code);
            }

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 99, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (Saving Target is Closed).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.CreditTransferAccountInvalid, (int)exception.Code);
            }
        }
Exemple #23
0
        public void RateWithdrawFees()
        {
            SavingsBookProduct product = new SavingsBookProduct()
            {
                WithdrawFeesType = OSavingsFeesType.Rate,
                RateWithdrawFeesMin = 0.01,
                RateWithdrawFeesMax = 0.05
            };

            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User(), new DateTime(2009, 01, 01), product, null) { RateWithdrawFees = 0.03 };
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);
            List<SavingEvent> withdrawEvents = saving.Withdraw(10, new DateTime(2009, 01, 02), "withdraw", new User(), false, null);

            Assert.AreEqual(1, withdrawEvents.Count);
            Assert.AreEqual(10, withdrawEvents[0].Amount.Value);
            Assert.AreEqual(0.3, ((ISavingsFees)withdrawEvents[0]).Fee.Value);
            Assert.AreEqual(989.7, saving.GetBalance().Value);
        }
Exemple #24
0
        public void SetUp()
        {
            ApplicationSettings dataParam = ApplicationSettings.GetInstance("");
            dataParam.DeleteAllParameters();
            dataParam.AddParameter(OGeneralSettings.ACCOUNTINGPROCESS, OAccountingProcesses.Cash);

            Currency currency = new Currency() { UseCents = true, Code = "SOM", Id = 1, IsPivot = true, Name = "SOM" };

            _bookProduct = new SavingsBookProduct
            {
                CalculAmountBase = OSavingCalculAmountBase.MinimalAmount,
                Id = 1,
                InterestBase = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfWeek,
                ManagementFeeFreq = new InstallmentType
                {
                    Id = 1,
                    Name = "Monthly",
                    NbOfDays = 0,
                    NbOfMonths = 1
                },
                AgioFeesFreq = new InstallmentType
                {
                    Id = 2,
                    Name = "Daily",
                    NbOfDays = 1,
                    NbOfMonths = 0
                },
                WithdrawFeesType = OSavingsFeesType.Flat,
                FlatWithdrawFees = 0,
                Currency = currency
            };

            _saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                                             new User(),
                                             new DateTime(2007, 08, 11), _bookProduct, null);
        }
Exemple #25
0
        public void UpdateAccountsBalanceSaving()
        {
            Assert.Ignore(); // Ru55
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User() { Id = 1 },
                new DateTime(2009, 01, 01), _savingsBookProduct, null)
            {
                Code = "S/CR/2009/SAVIN-1/BAR-2",
                Status = OSavingsStatus.Active,
                InterestRate = 0.01,
                FlatWithdrawFees = 3,
                FlatTransferFees = 3,
                AgioFees = 0.1
            };
            saving.Events[0].User = new User() { Id = 1 };
            saving.Id = _savingManager.Add(saving, new Person { Id = 6 });

            saving = (SavingBookContract)_savingManager.Select(saving.Id);

            saving.Closure(new DateTime(2009, 02, 01), new User { Id = 1 });
            saving.Withdraw(50, new DateTime(2009, 02, 01), "testWithdraw", new User { Id = 1 }, false, null);
            saving.Closure(new DateTime(2010, 01, 01), new User { Id = 1 });

            SavingBookContract retrievedSaving = (SavingBookContract)_savingManager.Select(saving.Id);
        }
Exemple #26
0
        public void TestSavingIsValid_InitialAmountCorrect()
        {
            //            Assert.Ignore();
            SavingBookContract saving = new SavingBookContract(
                                                                ApplicationSettings.GetInstance(""),

                                                                new User { Id = 6 },
                                                                TimeProvider.Today,
                                                                _savingsProduct,
                                                                null)
                                                                {
                                                                    InterestRate = 0.13,
                                                                    FlatWithdrawFees = 3,
                                                                    FlatTransferFees = 3,
                                                                    DepositFees = 5,
                                                                    CloseFees = 6,
                                                                    ManagementFees = 7,
                                                                    AgioFees = 6
                                                                };
            Client client = new Person { Id = 6, LastName = "El Fanidi", Branch = new Branch()};

            _savingManagerMock = new DynamicMock(typeof(SavingManager));
            _savingEventManagerMock = new DynamicMock(typeof(SavingEventManager));

            DynamicMock connectionMock = new DynamicMock(typeof(SqlConnection));
            DynamicMock transactionMock = new DynamicMock(typeof(SqlTransaction));
            connectionMock.SetReturnValue("BeginTransaction", transactionMock.MockInstance);

            _savingManagerMock.SetReturnValue("GetConnection", connectionMock.MockInstance);

            _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 1, 6);
            _savingManagerMock.ExpectAndReturn("Add", 1, saving, client, transactionMock.MockInstance);

            _savingServices = new SavingServices(
                                                    (SavingManager)_savingManagerMock.MockInstance,
                                                    (SavingEventManager)_savingEventManagerMock.MockInstance,
                                                     new User { Id = 6 }
                                                 );

            try
            {
                Assert.GreaterOrEqual(_savingServices.SaveContract(saving, client), 0);

                saving = new SavingBookContract(
                                                    ApplicationSettings.GetInstance(""),

                                                    new User { Id = 6 },
                                                    TimeProvider.Today,
                                                    _savingsProduct,
                                                    null)
                                                    {
                                                        InterestRate = 0.13,
                                                        FlatWithdrawFees = 3,
                                                        FlatTransferFees = 3,
                                                        DepositFees = 5,
                                                        CloseFees = 6,
                                                        ManagementFees = 7,
                                                        AgioFees = 6
                                                    };

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 2, 6);
                _savingManagerMock.ExpectAndReturn("Add", 2, saving, client, transactionMock.MockInstance);

                Assert.GreaterOrEqual(_savingServices.SaveContract(saving, client), 0);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.Fail(exception.Code.ToString());
            }
        }
Exemple #27
0
        public void CloseSaving()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),
                new User() { Id = 1 }, new DateTime(2009, 01, 01), _savingsBookProduct, null)
            {
                Code = "S/CR/2009/SAVIN-1/BAR-1",
                Status = OSavingsStatus.Active,
                InterestRate = 0.01,
                FlatWithdrawFees = 3
            };
            saving.InitialAmount = 1000;
            saving.EntryFees = 10;
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            User user = new User {Id = 1};
            saving.Events[0].User = user;
            saving.SavingsOfficer = user;
            saving.Id = _savingManager.Add(saving, new Person() { Id = 6 });

            saving.Status = OSavingsStatus.Closed;
            saving.ClosedDate = new DateTime(2009, 10, 01);
            _savingManager.UpdateStatus(saving.Id, saving.Status, saving.ClosedDate.Value);

            SavingBookContract retrievedSaving = (SavingBookContract)_savingManager.Select(saving.Id);

            Assert.AreEqual(OSavingsStatus.Closed, retrievedSaving.Status);
            Assert.AreEqual(new DateTime(2009, 10, 01), retrievedSaving.ClosedDate.Value);
        }
Exemple #28
0
        public void CalculateInterest_TwoOperation_In_OneDay()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id = 1,
                InterestBase = OSavingInterestBase.Monthly,
                InterestFrequency = OSavingInterestFrequency.EndOfYear,
                CalculAmountBase = OSavingCalculAmountBase.MinimalAmount,
                WithdrawFeesType = OSavingsFeesType.Flat,
                FlatWithdrawFees = 0
            };
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(),
                new DateTime(2009, 01, 01), null) { Product = product, InterestRate = 0.1, FlatWithdrawFees = 0 };
            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            saving.Withdraw(250, new DateTime(2009, 01, 15), "retrait", new User(), false, null);
            //            saving.Deposit(100, new DateTime(2009, 01, 15), "depot", new User(), true, false, OPaymentMethods.Cash, null, null);
            saving.Deposit(100, new DateTime(2009, 01, 15), "depot", new User(), true, false, OSavingsMethods.Cash, null, null);

            List<SavingInterestsAccrualEvent> list = new List<SavingInterestsAccrualEvent>();
            list = saving.CalculateInterest(new DateTime(2009, 02, 01), new User { Id = 1 });

            Assert.AreEqual(list.Count, 1);
            Assert.AreEqual(list[0].Amount, 75);
        }
Exemple #29
0
        public void TestSavingIsValid_InterestRate()
        {
            Assert.Ignore();
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""),  new User { Id = 6 },
                TimeProvider.Today, _savingsProduct, null) { FlatWithdrawFees = 3, FlatTransferFees = 3, DepositFees = 5, CloseFees = 6, ManagementFees = 7 };
            Client client = new Person { Id = 6, LastName = "El Fanidi" };

            _savingManagerMock = new DynamicMock(typeof(SavingManager));
            _savingEventManagerMock = new DynamicMock(typeof(SavingEventManager));

            _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 1, 6);
            _savingManagerMock.ExpectAndReturn("Add", 1, saving, client, null);

            _savingServices = new SavingServices((SavingManager)_savingManagerMock.MockInstance, (SavingEventManager)_savingEventManagerMock.MockInstance,
                 new User { Id = 6 });

            //Test InterestRate is valid (between min/max)
            saving.InterestRate = 0.11;
            try
            {
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.AgioFeesIsInvalid, (int)exception.Code);
            }

            try
            {
                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 2, 6);
                _savingManagerMock.ExpectAndReturn("Add", 2, saving, client, null);
                saving.InterestRate = 0.12;
                _savingServices.SaveContract(saving, client);

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 3, 6);
                _savingManagerMock.ExpectAndReturn("Add", 3, saving, client, null);
                saving.InterestRate = 0.13;
                _savingServices.SaveContract(saving, client);

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 4, 6);
                _savingManagerMock.ExpectAndReturn("Add", 4, saving, client, null);
                saving.InterestRate = 0.16;
                _savingServices.SaveContract(saving, client);

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 5, 6);
                _savingManagerMock.ExpectAndReturn("Add", 5, saving, client, null);
                saving.InterestRate = 0.19;
                _savingServices.SaveContract(saving, client);

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 6, 6);
                _savingManagerMock.ExpectAndReturn("Add", 6, saving, client, null);
                saving.InterestRate = 0.20;
                _savingServices.SaveContract(saving, client);

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 7, 6);
                _savingManagerMock.ExpectAndReturn("Add", 7, saving, client, null);
                saving.InterestRate = 0.21;
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.Fail(exception.Code.ToString());
            }
            try
            {

                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 8, 6);
                _savingManagerMock.ExpectAndReturn("Add", 8, saving, client, null);
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.InterestRateIsInvalid, (int)exception.Code);
            }

            //Test InterestRate is valid (equals to required value)
            //Create a product with min/max InterestRate
            _savingsProduct.InterestRate = 0.15;
            _savingsProduct.InterestRateMin = null;
            _savingsProduct.InterestRateMax = null;

            saving.InterestRate = 0.14;
            try
            {
                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 9, 6);
                _savingManagerMock.ExpectAndReturn("Add", 9, saving, client, null);
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.InterestRateIsInvalid, (int)exception.Code);
            }

            _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 10, 6);
            _savingManagerMock.ExpectAndReturn("Add", 10, saving, client, null);
            saving.InterestRate = 0.15;
            _savingServices.SaveContract(saving, client);

            saving.InterestRate = 0.16;
            try
            {
                _savingManagerMock.ExpectAndReturn("GetNumberOfSavings", 11, 6);
                _savingManagerMock.ExpectAndReturn("Add", 11, saving, client, null);
                _savingServices.SaveContract(saving, client);
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.InterestRateIsInvalid, (int)exception.Code);
            }
        }
Exemple #30
0
        public void PostingInterests_OnePosting()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id = 1,
                InterestBase = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfYear
            };

            SavingBookContract saving = new SavingBookContract(
                                                                ApplicationSettings.GetInstance(""),
                                                                new User(),
                                                                new DateTime(2009, 01, 01),
                                                                null)
                                                                {
                                                                    Product = product,
                                                                    InterestRate = 0.1
                                                                };

            List<SavingInterestsPostingEvent> list = new List<SavingInterestsPostingEvent>();
            list = saving.PostingInterests(new DateTime(2010, 01, 01), new User { Id = 1 });

            Assert.AreEqual(list.Count, 1);
        }
Exemple #31
0
        public void CalculateInterest_OneMonth()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id = 1,
                InterestBase = OSavingInterestBase.Monthly,
                InterestFrequency = OSavingInterestFrequency.EndOfYear,
                CalculAmountBase = OSavingCalculAmountBase.MinimalAmount
            };
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(),
                new DateTime(2009, 01, 01), null) { Product = product, InterestRate = 0.1 };
            saving.FirstDeposit(100, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            List<SavingInterestsAccrualEvent> list = new List<SavingInterestsAccrualEvent>();
            list = saving.CalculateInterest(new DateTime(2009, 02, 01), new User { Id = 1 });

            Assert.AreEqual(list.Count, 1);
            Assert.AreEqual(list[0].Amount, 10);
        }