public static HolidayTakenNotPaidCalculationRequestModel GetValidRp1RequestData() { var holidayTakenNotPaidCalculationRequestModel = new HolidayTakenNotPaidCalculationRequestModel(InputSource.Rp1, new DateTime(2018, 01, 10), new DateTime(2018, 01, 03), new DateTime(2017, 12, 20) , new DateTime(2017, 12, 29), 306.85m, new List <string> { "1", "2", "3", "4", "5" }, 6, true); return(holidayTakenNotPaidCalculationRequestModel); }
private void UpdateWeek(Week week, DateTime date, decimal amount, HolidayTakenNotPaidCalculationRequestModel data) { DateTime prefPeriodStartDate = data.InsolvencyDate.Date.AddMonths(-4); week.EmploymentDays += amount; if (date >= prefPeriodStartDate && date <= data.InsolvencyDate) { week.EmploymentDaysInPrefPeriod += amount; } }
public async Task PerformHolidayTakenNotPaidCalculation( HolidayTakenNotPaidCalculationRequestModel requestModel, string inputSource, decimal maxDaysInCurrentHolidayYear, decimal maxDaysInTotal, HolidayTakenNotPaidResponseDTO expectedResult ) { //Act 1 var request = new List <HolidayTakenNotPaidCalculationRequestModel>() { requestModel }; var actualResult1 = await _holidayTakenNotPaidCalculationService.PerformCalculationAsync( request, inputSource, maxDaysInCurrentHolidayYear, maxDaysInTotal, new DateTime(2018, 1, 1), _options); //Assert 1 actualResult1.InputSource.Should().Be(expectedResult.InputSource); actualResult1.StatutoryMax.Should().Be(expectedResult.StatutoryMax); actualResult1.WeeklyResult.Count.Should().Be(expectedResult.WeeklyResult.Count); for (var expectedCalcResultIndex = 0; expectedCalcResultIndex < expectedResult.WeeklyResult.Count; expectedCalcResultIndex++) { for (var actualCalcResultIndex = expectedCalcResultIndex; actualCalcResultIndex <= expectedCalcResultIndex; actualCalcResultIndex++) { actualResult1.WeeklyResult[expectedCalcResultIndex].WeekNumber.Should() .Be(expectedResult.WeeklyResult[expectedCalcResultIndex].WeekNumber); actualResult1.WeeklyResult[expectedCalcResultIndex].PayDate.Should() .Be(expectedResult.WeeklyResult[expectedCalcResultIndex].PayDate); actualResult1.WeeklyResult[expectedCalcResultIndex].MaximumEntitlement.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].MaximumEntitlement); actualResult1.WeeklyResult[expectedCalcResultIndex].EmployerEntitlement.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].EmployerEntitlement); actualResult1.WeeklyResult[expectedCalcResultIndex].GrossEntitlement.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].GrossEntitlement); actualResult1.WeeklyResult[expectedCalcResultIndex].IsTaxable.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].IsTaxable); actualResult1.WeeklyResult[expectedCalcResultIndex].TaxDeducted.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].TaxDeducted); actualResult1.WeeklyResult[expectedCalcResultIndex].NiDeducted.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].NiDeducted); actualResult1.WeeklyResult[expectedCalcResultIndex].NetEntitlement.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].NetEntitlement); actualResult1.WeeklyResult[expectedCalcResultIndex].MaximumDays.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].MaximumDays); actualResult1.WeeklyResult[expectedCalcResultIndex].EmploymentDays.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].EmploymentDays); actualResult1.WeeklyResult[expectedCalcResultIndex].MaximumEntitlementIn4MonthPeriod.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].MaximumEntitlementIn4MonthPeriod); actualResult1.WeeklyResult[expectedCalcResultIndex].EmployerEntitlementIn4MonthPeriod.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].EmployerEntitlementIn4MonthPeriod); actualResult1.WeeklyResult[expectedCalcResultIndex].GrossEntitlementIn4Months.Should().Be( expectedResult.WeeklyResult[expectedCalcResultIndex].GrossEntitlementIn4Months); } } }
public async Task PostAsync_FailsWithBadRequest_WhenThereIsAHtnpValidationError(HolidayTakenNotPaidCalculationRequestModel htnpRequest, string expectedErrorMessage) { //Arrange var request = new HolidayCalculationRequestModel() { Htnp = new List <HolidayTakenNotPaidCalculationRequestModel>() { htnpRequest } }; var controller = new HolidayController(_service.Object, _mockLogger.Object, _confOptions); //Act var result = await controller.PostAsync(request); //Assert var badRequestObjectRequest = result.Should().BeOfType <BadRequestObjectResult>().Subject; badRequestObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.BadRequest); _mockLogger.Verify(x => x.Log( LogLevel.Error, It.IsAny <EventId>(), It.Is <object>(v => v.ToString().Contains(expectedErrorMessage)), null, It.IsAny <Func <object, Exception, string> >() )); }
private async Task SelectDaysAndConvertToWeeks(IList <Week> weeks, IList <DateTime> htnpDays, HolidayTakenNotPaidCalculationRequestModel firstRequest, decimal daysToSelect) { decimal baseSelected = weeks.Sum(x => x.EmploymentDays); for (int i = 0; i < htnpDays.Count; i++) { var payDate = await htnpDays[i].GetPayDay((DayOfWeek)firstRequest.PayDay); decimal numSelected = weeks.Sum(x => x.EmploymentDays) - baseSelected; decimal amountSelected = 0m; decimal amountUnselected = 0m; if (numSelected < Math.Floor(daysToSelect)) { amountSelected = 1m; } else if (numSelected >= Math.Ceiling(daysToSelect)) { amountUnselected = 1m; } else { amountSelected = daysToSelect % 1m; amountUnselected = 1m - amountSelected; } if (amountSelected > 0m) { Week weekSelected = GetWeek(weeks, payDate, true); UpdateWeek(weekSelected, htnpDays[i], amountSelected, firstRequest); } if (amountUnselected > 0m) { Week weekUnselected = GetWeek(weeks, payDate, false); UpdateWeek(weekUnselected, htnpDays[i], amountUnselected, firstRequest); } } }