public DateTime CalculateNextSalaryDate(SalaryDateCalculationDto date) { OffDayProvider.Providers.Add(new WeekendProvider()); switch (date.PaymentFrequency) { case SalaryFrequency.SpecificDayofMonth: return(date.Current.SpecificDayofMonth(date.Day)); case SalaryFrequency.FirstWorkingdayofMonth: return(date.Current.FirstWorkingdayofMonth()); case SalaryFrequency.LastWorkingDayofMonth: return(date.Current.LastWorkingdayofMonth()); case SalaryFrequency.DayBeforeLastWorkingDay: return(date.Current.DayBeforeLastWorkingDay()); case SalaryFrequency.FirstXDay: return(date.Current.FirstXDay(date.Day)); case SalaryFrequency.LastXDay: return(date.Current.LastXDay(date.Day)); case SalaryFrequency.NthXDay: return(date.Current.NthXDay(date.Day, date.Week)); case SalaryFrequency.NthWeeksXDay: return(date.Current.NthWeeksXDay(date.Day, date.Week)); } return(DateTime.Now); }
public IHttpActionResult Index(SalaryDateCalculationDto input) { Calculate calculate = new Calculate(); var data = calculate.CalculateNextSalaryDate(input); return(Ok(data.Date)); }
public IActionResult CalculateNextSalaryDate(DateTime currentDate, [FromBody] SalaryDateCalculationDto dateCalculationDto) { Calculator.SetCurrentDateTime(currentDate); var Result = Calculator.CalculateNextSalaryDate(dateCalculationDto); return(Ok(new SalaryDateTestModel { CurrentDateTime = currentDate, Day = dateCalculationDto.Day, Frequency = dateCalculationDto.PaymentFrequency, NextSalaryDateTime = Result, Week = dateCalculationDto.Week })); }
public void NthWeeksXDayExpectException() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 1, Week = 1, Current = new DateTime(2017, 8, 10), PaymentFrequency = SalaryFrequency.NthWeeksXDay }; // -- act calculate.CalculateNextSalaryDate(input); //-- Assert }
public void DayBeforeLastWorkingDay() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 0, Week = 0, Current = new DateTime(2017, 6, 8), PaymentFrequency = SalaryFrequency.DayBeforeLastWorkingDay }; var expected = "6/29/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
public void LastWorkingDayofMonthForSeptember() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 0, Week = 0, Current = new DateTime(2017, 9, 20), PaymentFrequency = SalaryFrequency.LastWorkingDayofMonth }; var expected = "9/29/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
public void NthWeeksXDay() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 5, Week = 5, Current = new DateTime(2017, 6, 14), PaymentFrequency = SalaryFrequency.NthWeeksXDay }; var expected = "6/30/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
public void SpecificDayofMonthDayBeforeCurrentDay() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 14, Week = 0, Current = new DateTime(2017, 7, 20), PaymentFrequency = SalaryFrequency.SpecificDayofMonth }; var expected = "8/14/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
public void LastXDayForAugust() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 1, Week = 0, Current = new DateTime(2017, 8, 18), PaymentFrequency = SalaryFrequency.LastXDay }; var expected = "8/28/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
public void FirstXDayExpectThisMonth() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 4, Week = 0, Current = new DateTime(2017, 7, 1), PaymentFrequency = SalaryFrequency.FirstXDay }; var expected = "7/6/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
public void FirstWorkingdayofMonthForFirstDayIsWeekend() { //-- Arrange Calculate calculate = new Calculate(); var input = new SalaryDateCalculationDto { Day = 0, Week = 0, Current = new DateTime(2017, 10, 1), PaymentFrequency = SalaryFrequency.FirstWorkingdayofMonth }; var expected = "10/2/2017"; // -- act var actual = calculate.CalculateNextSalaryDate(input).ToShortDateString(); //-- Assert Assert.AreEqual(expected, actual); }
/// <summary> /// /// </summary> /// <param name="date"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public DateTime CalculateNextSalaryDate(SalaryDateCalculationDto date) { DateTime Result; switch (date.PaymentFrequency) { case SalaryFrequency.SpecificDayofMonth: Result = CurrentTime.SpecificDayOfMonth(date.Day); break; case SalaryFrequency.LastWorkingDayofMonth: Result = CurrentTime.LastWorkingDayOfMonth(); break; case SalaryFrequency.DayBeforeLastWorkingDay: Result = CurrentTime.DayBeforeLastWorkingDay(); break; case SalaryFrequency.FirstWorkingdayofMonth: Result = CurrentTime.FirstWorkingDayOfMonth(); break; case SalaryFrequency.FirstXDay: Result = CurrentTime.FirstXDay(date.Day, date.Week); break; case SalaryFrequency.LastXDay: Result = CurrentTime.LastXDay(date.Day, date.Week); break; default: throw new ArgumentOutOfRangeException(); } return(Result); }