Esempio n. 1
0
        public void CalculateInterest_ThirtyDay()
        {
            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 <SavingInterestsAccrualEvent> list = new List <SavingInterestsAccrualEvent>();

            list = saving.CalculateInterest(new DateTime(2009, 01, 31), new User {
                Id = 1
            });

            Assert.AreEqual(31, list.Count);
        }
Esempio n. 2
0
        public void CalculateInterest_OneWeek()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id                = 1,
                InterestBase      = OSavingInterestBase.Weekly,
                InterestFrequency = OSavingInterestFrequency.EndOfYear,
                CalculAmountBase  = OSavingCalculAmountBase.MinimalAmount
            };
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(),
                                                               new DateTime(2009, 01, 05), null)
            {
                Product = product, InterestRate = 0.1
            };

            saving.FirstDeposit(1000, new DateTime(2009, 01, 01), null, new User(), Teller.CurrentTeller);

            List <SavingInterestsAccrualEvent> list = new List <SavingInterestsAccrualEvent>();

            list = saving.CalculateInterest(new DateTime(2009, 01, 12), new User {
                Id = 1
            });

            Assert.AreEqual(list.Count, 1);
            Assert.AreEqual(list[0].Amount, 100);
        }
Esempio n. 3
0
        public void CalculateInterest_TwoOperation_In_OneDay()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id                = 1,
                InterestBase      = OSavingInterestBase.Weekly,
                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, 02), "retrait", new User(), false, null);
//            saving.Deposit(100, new DateTime(2009, 02, 01), "depot", new User(), true, false, OPaymentMethods.Cash, null, null);
            saving.Deposit(100, new DateTime(2009, 02, 01), "depot", new User(), true, false, OSavingsMethods.Cash, null, null);

            List <SavingInterestsAccrualEvent> list = new List <SavingInterestsAccrualEvent>();

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

            Assert.AreEqual(list.Count, 1);
            Assert.AreEqual(list[0].Amount, 75);
        }
Esempio n. 4
0
        public void CalculateInterest_OneMonth_Withdraw()
        {
            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(100, new DateTime(2009, 01, 15), "depot", new User(), false, 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, 90);
        }
Esempio n. 5
0
        public void PostingInterests_TenPosting()
        {
//            Assert.Ignore();
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id                = 1,
                InterestBase      = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfDay,
                Periodicity       = new InstallmentType("Daily", 1, 0)
            };
            DateTime           postingDate = new DateTime(2009, 01, 10);
            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 <SavingInterestsAccrualEvent> savingInterestsAccrualEvents = saving.CalculateInterest(
                new DateTime(2009, 01, 10),
                new User {
                Id = 1
            });

            foreach (SavingInterestsAccrualEvent accrualEvent in savingInterestsAccrualEvents)
            {
                saving.Events.Add(accrualEvent);
            }

            saving.NextMaturity = saving.CreationDate.AddDays(-1);

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


            Assert.AreEqual(10, saving.Events.FindAll(item => item is SavingInterestsPostingEvent).Count);
        }
Esempio n. 6
0
        public void PostingInterests_ThreePosting()
        {
//            Assert.Ignore();
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id                = 1,
                InterestBase      = OSavingInterestBase.Daily,
                InterestFrequency = OSavingInterestFrequency.EndOfWeek,
                Periodicity       = new InstallmentType("Weekly", 7, 0)
            };
            User user = new User()
            {
                Id = 1
            };
            DateTime           creationDate = new DateTime(2009, 01, 01);
            DateTime           postingDate  = new DateTime(2009, 01, 26);
            SavingBookContract saving       = new SavingBookContract(
                ApplicationSettings.GetInstance(""),
                user,
                creationDate,
                null)
            {
                Product      = product,
                InterestRate = 0.1
            };

            saving.FirstDeposit(1000, saving.CreationDate, 0, user, new Teller());
            List <SavingInterestsAccrualEvent> accrualEvents = saving.CalculateInterest(postingDate, user);

            foreach (var accrualEvent in accrualEvents)
            {
                saving.Events.Add(accrualEvent);
            }
            List <SavingInterestsPostingEvent> list          = new List <SavingInterestsPostingEvent>();
            List <SavingInterestsPostingEvent> postingEvents = new List <SavingInterestsPostingEvent>();

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

            Assert.AreEqual(3, postingEvents.Count);
        }
        public void TestAccrualEvent()
        {
            int i = 10;

            foreach (SavingEvent savingEvent in _saving.CalculateInterest(new DateTime(2009, 01, 05), _user))
            {
                savingEvent.Id = i;
                savingEvent.Id = _savingEventManager.Add(savingEvent, _saving.Id);
                SavingEvent retrievedEvent = _savingEventManager.SelectEvents(_saving.Id, _saving.Product).Find(item => item.Id == savingEvent.Id);

                CompareEvent(savingEvent, retrievedEvent);

                i++;
            }
        }
Esempio n. 8
0
        public void PostingInterests_OnePosting()
        {
            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           closureDate = new DateTime(2009, 02, 01);
            SavingBookContract saving      = new SavingBookContract(
                ApplicationSettings.GetInstance(""),
                user,
                new DateTime(2009, 01, 01),
                null
                )
            {
                Product      = product,
                InterestRate = 0.1
            };

            saving.NextMaturity = DateCalculationStrategy.GetNextMaturity(saving.CreationDate.Date,
                                                                          saving.Periodicity, 1);

            List <SavingInterestsAccrualEvent> savingInterestsAccrualEvents =
                saving.CalculateInterest(closureDate, user);

            foreach (var accrualEvent in savingInterestsAccrualEvents)
            {
                saving.Events.Add(accrualEvent);
            }
            List <SavingInterestsPostingEvent> list = new List <SavingInterestsPostingEvent>();

            list = saving.PostingInterests(closureDate, user);

            Assert.AreEqual(1, list.Count);
        }
Esempio n. 9
0
        public void CalculateInterest_NoDay()
        {
            SavingsBookProduct product = new SavingsBookProduct
            {
                Id                = 1,
                InterestBase      = OSavingInterestBase.Weekly,
                InterestFrequency = OSavingInterestFrequency.EndOfYear,
                CalculAmountBase  = OSavingCalculAmountBase.MinimalAmount
            };
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(),
                                                               new DateTime(2009, 01, 05), null)
            {
                Product = product, InterestRate = 0.1
            };

            List <SavingInterestsAccrualEvent> list = new List <SavingInterestsAccrualEvent>();

            list = saving.CalculateInterest(new DateTime(2009, 01, 05), new User {
                Id = 1
            });

            Assert.AreEqual(list.Count, 0);
        }
Esempio n. 10
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);
        }