예제 #1
0
        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);
        }
예제 #2
0
        public IHttpActionResult Index(SalaryDateCalculationDto input)
        {
            Calculate calculate = new Calculate();

            var data = calculate.CalculateNextSalaryDate(input);

            return(Ok(data.Date));
        }
예제 #3
0
        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
            }));
        }
예제 #4
0
        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
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        /// <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);
        }