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, 30), 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); }