Ejemplo n.º 1
0
        public void TestGetExpectedRent()
        {
            //most straight foward example
            var firstOfYear = new DateTime(DateTime.Today.Year, 1, 1);

            var testSubject = new Rent(null, firstOfYear, 12, new Pecuniam(700), new Pecuniam(0));

            var testResult = testSubject.GetExpectedTotalRent(new DateTime(DateTime.Today.Year, 3,1));
            //only two whole months have passed but rent's due on the first
            Assert.AreEqual(new Pecuniam(700*3), testResult);

            //after 15 days only first rent is due
            testResult = testSubject.GetExpectedTotalRent(firstOfYear.AddDays(15));
            Assert.AreEqual(new Pecuniam(700), testResult);

            //back the signing date to middle of Dec
            var newSigningDate = firstOfYear.AddDays(-16);
            testSubject = new Rent(null, newSigningDate, 12, new Pecuniam(700), new Pecuniam(0));

            //this should be only the pro-rated amount, first full month is due tommorrow
            testResult = testSubject.GetExpectedTotalRent(newSigningDate.AddDays(15));
            Assert.AreEqual(new Pecuniam(350), testResult);

            //add another day - this should be pro-rated amount plus first month
            testResult = testSubject.GetExpectedTotalRent(firstOfYear.AddDays(16));
            Assert.AreEqual(new Pecuniam(350 + 700), testResult);

            //move to first of Feb - this should be pro-rated amount plus two months rent
            testResult = testSubject.GetExpectedTotalRent(new DateTime(DateTime.Today.Year, 2, 1));
            Assert.AreEqual(new Pecuniam(350 + 700*2), testResult);

            //middle of march -should be prorated amount plus three months
            testResult = testSubject.GetExpectedTotalRent(new DateTime(DateTime.Today.Year, 3, 15));
            Assert.AreEqual(new Pecuniam(350 + 700*3), testResult);

            //on the last day of march - should still be the same
            testResult = testSubject.GetExpectedTotalRent(new DateTime(DateTime.Today.Year, 4, 1).AddDays(-1));
            Assert.AreEqual(new Pecuniam(350 + 700 * 3), testResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates random <see cref="Rent"/> instance with a history and adds
        /// it to the <see cref="Opes.HomeDebt"/> collection.
        /// </summary>
        /// <param name="stdDevAsPercent"></param>
        /// <remarks>
        /// src [http://www.nmhc.org/Content.aspx?id=4708]
        /// </remarks>
        protected internal Pecuniam AddRent(double stdDevAsPercent = DF_STD_DEV_PERCENT)
        {
            if (!_isRenting)
                return Pecuniam.Zero;
            //create a rent object
            var avgRent = (double)Rent.GetAvgAmericanRentByYear(null).Amount;

            var randRent =
                new Pecuniam(
                    (decimal) GetRandomFactorValue(FactorTables.HomeDebt, _homeDebtFactor, stdDevAsPercent, avgRent));
            var term = 12;
            var randDate = Etx.Date(0, DateTime.Today.AddDays(-2));
            var rent = new Rent(_amer.Address, randDate, term, randRent, Etx.CoinToss ? new Pecuniam(250) : new Pecuniam(500))
            {
                Description = $"{term}-Month Lease"
            };
            _amer.Address.IsLeased = true;
            //create payment history until current
            var firstPmt = rent.GetMinPayment(randDate);
            rent.PayRent(randDate.AddDays(1), firstPmt);

            var rentDueDate = randDate.Month == 12
                ? new DateTime(randDate.Year + 1, 1, 1)
                : new DateTime(randDate.Year, randDate.Month + 1, 1);

            while (rentDueDate < DateTime.Today)
            {
                var paidRentOn = rentDueDate;
                //move the date rent was paid to some late-date when person acts irresponsible
                if (_amer.Personality.GetRandomActsIrresponsible())
                    paidRentOn = paidRentOn.AddDays(Etx.IntNumber(5, 15));

                rent.PayRent(paidRentOn, randRent, GetPaymentNote(rent.Id));
                rentDueDate = rentDueDate.AddMonths(1);
            }

            HomeDebt.Add(rent);
            return randRent;
        }
Ejemplo n.º 3
0
        public void TestGetMinPayment()
        {
            //most straight foward example
            var firstOfYear = new DateTime(DateTime.Today.Year, 1, 1);

            var testSubject = new Rent(null, firstOfYear, 12,new Pecuniam(700), new Pecuniam(0));
            //first rent due immediately
            testSubject.PayRent(firstOfYear, new Pecuniam(-700));

            //15 days later
            var testResult = testSubject.GetMinPayment(firstOfYear.AddDays(15));

            //paid first month so nothing should be due
            Assert.AreEqual(0M, testResult.Amount);

            //move signing back to mid Dec of prev year
            var newSigningDate = new DateTime(DateTime.Today.Year-1, 12, 14);
            testSubject = new Rent(null, newSigningDate, 12, new Pecuniam(700), new Pecuniam(0));

            //pro-rated amount should be due immediately
            testResult = testSubject.GetMinPayment(newSigningDate);
            Assert.AreEqual(new Pecuniam(-396.67M), testResult);

            //should be the same until first of next month
            testResult = testSubject.GetMinPayment(new DateTime(DateTime.Today.Year - 1, 12, 31));
            Assert.AreEqual(new Pecuniam(-396.67M), testResult);

            //first month rent due
            testResult = testSubject.GetMinPayment(firstOfYear);
            Assert.AreEqual(new Pecuniam(-396.67M + -700), testResult);

            //pay prorated amt
            testSubject.PayRent(new DateTime(DateTime.Today.Year - 1, 12, 31), new Pecuniam(-396.67M));

            //should still be due one months
            testResult = testSubject.GetMinPayment(firstOfYear);
            Assert.AreEqual(new Pecuniam(-700), testResult);

            //pay first month at exact same time only as another transaction
            testSubject.PayRent(new DateTime(DateTime.Today.Year - 1, 12, 31), new Pecuniam(-700));

            //since rent is not due until tommorrow - there is a 700 credit
            testResult = testSubject.GetMinPayment(new DateTime(DateTime.Today.Year - 1, 12, 31));
            Assert.AreEqual(700.0M, testResult.Amount );

            //very next day should be current
            testResult = testSubject.GetMinPayment(new DateTime(DateTime.Today.Year, 1, 1));
            Assert.AreEqual(0M, testResult.Amount);

            //pay some part of next month ahead of due
            testSubject.PayRent(new DateTime(DateTime.Today.Year, 1, 18), new Pecuniam(-300));

            //should register as a credit
            testResult = testSubject.GetMinPayment(new DateTime(DateTime.Today.Year, 1, 18));
            Assert.AreEqual(new Pecuniam(300), testResult);

            //at first of next month rent less the credit should be due
            testResult = testSubject.GetMinPayment(new DateTime(DateTime.Today.Year, 2, 1));
            Assert.AreEqual(new Pecuniam(300-700), testResult);
        }