Пример #1
0
        public void GetContractCodesForClient()
        {
            const int tiersId = 6;
            _savingManagerMock = new DynamicMock(typeof(SavingManager));
            _savingManagerMock.ExpectAndReturn("SelectClientSavingBookCodes",
                                               new[]
                                                   {
                                                       new KeyValuePair<int, string>(1, "S/BC/2007/SAVIN-1/ELFA-6")
                                                   },
                                               tiersId, 1
                );

            var savingService = new SavingServices(
                (SavingManager)_savingManagerMock.MockInstance,
                null,
                new User()
                );
            var savings = savingService.SelectClientSavingBookCodes(tiersId, 1);
            Assert.AreEqual(1, savings.Length);
            var saving = savings[0];
            Assert.AreEqual(1, saving.Key);
            Assert.AreEqual("S/BC/2007/SAVIN-1/ELFA-6", saving.Value);
        }
Пример #2
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);
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
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));
        }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }
Пример #8
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);
            }
        }
Пример #9
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);
            }
        }
Пример #10
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());
            }
        }
Пример #11
0
        public LoanServices(User pUser)
            : base(pUser)
        {
            _user = pUser;
            _loanManager = new LoanManager(pUser);
            _instalmentManager = new InstallmentManager(pUser);
            _clientManager = new ClientManager(pUser, true, true);
            _branchService = new BranchService(pUser);
            _econimcActivityServices = new EconomicActivityServices(pUser);
            _ePs = ServicesProvider.GetInstance().GetEventProcessorServices();
            _accountingServices = new AccountingServices(pUser);
            _fundingLineServices = new FundingLineServices(pUser);
            _savingServices = new SavingServices(pUser);
            _savingEventManager = new SavingEventManager(pUser);

            var settings = ApplicationSettings.GetInstance(string.Empty);
            var nonWorkingDate = NonWorkingDateSingleton.GetInstance(string.Empty);
            _configurationFactory = new OctopusScheduleConfigurationFactory(nonWorkingDate, settings);

            MefContainer.Current.Bind(this);
        }
Пример #12
0
 public LoanServices(User pUser)
     : base(pUser)
 {
     _user = pUser;
     _loanManager = new LoanManager(pUser);
     _instalmentManager = new InstallmentManager(pUser);
     _clientManager = new ClientManager(pUser, true, true);
     _branchService = new BranchService(pUser);
     _econimcActivityServices = new EconomicActivityServices(pUser);
     _ePs = ServicesProvider.GetInstance().GetEventProcessorServices();
     _accountingServices = new AccountingServices(pUser);
     _fundingLineServices = new FundingLineServices(pUser);
     _savingServices = new SavingServices(pUser);
     _savingEventManager = new SavingEventManager(pUser);
 }