Пример #1
0
        public async Task PostAsync_Succeeds_WithNoAPData()
        {
            //Arrange
            var request = new NoticePayCompositeCalculationRequestModel
            {
                Cnp = new CompensatoryNoticePayCalculationRequestModel
                {
                    InsolvencyEmploymentStartDate = new DateTime(2016, 02, 01),
                    InsolvencyDate  = new DateTime(2018, 6, 1),
                    DismissalDate   = new DateTime(2018, 06, 05),
                    DateNoticeGiven = new DateTime(2018, 06, 01),
                    WeeklyWage      = 330.25m,
                    ShiftPattern    = new List <string> {
                        "1", "2", "3", "4", "5"
                    },
                    IsTaxable    = true,
                    DateOfBirth  = new DateTime(1990, 1, 1),
                    DeceasedDate = null
                },
                Nwnp = new List <NoticeWorkedNotPaidCalculationRequestModel>(),
            };
            var response = new NoticePayCompositeCalculationResponseDTO();

            _service.Setup(m => m.PerformNoticePayCompositeCalculationAsync(request, _confOptions)).ReturnsAsync(response);
            var controller = new NoticeController(_service.Object, _mockLogger.Object, _confOptions);

            //Act
            var result = await controller.PostAsync(request);

            //Assert
            var okObjectRequest = result.Should().BeOfType <OkObjectResult>().Subject;

            okObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK);
        }
Пример #2
0
        public async Task PostAsync_ReturnsOkResult_When_RequestData_HasBothCNPandNWNPData()
        {
            //Arrange
            var controller = new NoticeController(_service.Object, _mockLogger.Object, _confOptions);
            var data       = new NoticePayCompositeCalculationRequestModel()
            {
                Cnp  = CompensatoryNoticePayControllerTestsDataGenerator.GetValidRequest(),
                Nwnp = new List <NoticeWorkedNotPaidCalculationRequestModel>()
                {
                    NoticeWorkedNotPaidControllerTestsDataGenerator.GetValidRP1Request(),
                NoticeWorkedNotPaidControllerTestsDataGenerator.GetValidRP14aRequest()
                }
            };
            var response = new NoticePayCompositeCalculationResponseDTO();

            _service.Setup(s => s.PerformNoticePayCompositeCalculationAsync(data, _confOptions))
            .ReturnsAsync(It.IsAny <NoticePayCompositeCalculationResponseDTO>());

            //Act

            var result = await controller.PostAsync(data);

            //Assert
            var okRequestObjectRequest = result.Should().BeOfType <OkObjectResult>().Subject;

            _mockLogger.Verify(x => x.Log(
                                   LogLevel.Information,
                                   It.IsAny <EventId>(),
                                   It.Is <object>(v =>
                                                  v.ToString().Contains("Calculation performed successfully for the request data provided")),
                                   null,
                                   It.IsAny <Func <object, Exception, string> >()
                                   ));
            okRequestObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK);
        }
Пример #3
0
        public async Task PostAsync_ReturnsBadRequest_When_RequestData_HaveInvalidCNPData(CompensatoryNoticePayCalculationRequestModel request, string expectedErrorMessage)
        {
            //Arrange
            var controller = new NoticeController(_service.Object, _mockLogger.Object, _confOptions);
            var data       = new NoticePayCompositeCalculationRequestModel()
            {
                Cnp  = request,
                Nwnp = null
            };

            //Act

            var result = await controller.PostAsync(data);

            //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> >()
                                   ));
        }
Пример #4
0
        public async Task PostAsync_SucceedsWithOverlappingPeriodsInDifferentInputSources()
        {
            //Arrange
            var request = new NoticePayCompositeCalculationRequestModel()
            {
                Cnp  = null,
                Nwnp = new List <NoticeWorkedNotPaidCalculationRequestModel>()
                {
                    new NoticeWorkedNotPaidCalculationRequestModel()
                    {
                        InputSource         = InputSource.Rp1,
                        EmploymentStartDate = new DateTime(2015, 8, 2),
                        InsolvencyDate      = new DateTime(2018, 7, 20),
                        DateNoticeGiven     = new DateTime(2018, 7, 20),
                        DismissalDate       = new DateTime(2018, 7, 20),
                        UnpaidPeriodFrom    = new DateTime(2018, 7, 1),
                        UnpaidPeriodTo      = new DateTime(2018, 7, 8),
                        WeeklyWage          = 320,
                        ShiftPattern        = new List <string> {
                            "1", "2", "3", "4", "5"
                        },
                        PayDay    = 6,
                        IsTaxable = true
                    },
                    new NoticeWorkedNotPaidCalculationRequestModel()
                    {
                        InputSource         = InputSource.Rp14a,
                        EmploymentStartDate = new DateTime(2015, 8, 2),
                        InsolvencyDate      = new DateTime(2018, 7, 20),
                        DateNoticeGiven     = new DateTime(2018, 7, 20),
                        DismissalDate       = new DateTime(2018, 7, 20),
                        UnpaidPeriodFrom    = new DateTime(2018, 7, 8),
                        UnpaidPeriodTo      = new DateTime(2018, 7, 10),
                        WeeklyWage          = 320,
                        ShiftPattern        = new List <string> {
                            "1", "2", "3", "4", "5"
                        },
                        PayDay    = 6,
                        IsTaxable = true
                    }
                }
            };

            var response = NoticeControllerTestsDataGenerator.GetValidResponseData();

            _service.Setup(m => m.PerformNoticePayCompositeCalculationAsync(request, _confOptions)).ReturnsAsync(response);
            var controller = new NoticeController(_service.Object, _mockLogger.Object, _confOptions);

            //Act
            var result = await controller.PostAsync(request);

            //Assert
            var okObjectRequest = result.Should().BeOfType <OkObjectResult>().Subject;

            okObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK);
        }
        public async Task PerformNoticeCalculationTests(
            NoticePayCompositeCalculationRequestModel req1, NoticePayCompositeCalculationResponseDTO res1,
            NoticePayCompositeCalculationRequestModel req2, NoticePayCompositeCalculationResponseDTO res2,
            NoticePayCompositeCalculationRequestModel req3, NoticePayCompositeCalculationResponseDTO res3)
        {
            //arrange
            var inputDataList = new List <NoticePayCompositeCalculationRequestModel>()
            {
                req1, req2, req3
            };
            var expectedOutputList = new List <NoticePayCompositeCalculationResponseDTO>()
            {
                res1, res2, res3
            };

            //add selected weeks to the expectedOutputList
            expectedOutputList[0].Cnp.WeeklyResults.ToList().ForEach(x => x.IsSelected = true);
            expectedOutputList[1].Nwnp.rp14aResults.WeeklyResult.ToList().ForEach(x => x.IsSelected = true);
            expectedOutputList[2].Nwnp.rp14aResults.WeeklyResult.ToList().ForEach(x => x.IsSelected = true);
            expectedOutputList[2].Cnp.WeeklyResults.ForEach(x => x.IsSelected = true);
            expectedOutputList[2].Nwnp.rp14aResults.WeeklyResult.ForEach(x => x.IsSelected = true);


            var actualOutputList = new List <NoticePayCompositeCalculationResponseDTO>();

            int i = 0;

            foreach (var data in inputDataList)
            {
                //act
                var res = await _noticeCalculationsServiceTests.PerformNoticePayCompositeCalculationAsync(data, _options);

                //assert for empty CNP/NWNP in output & selectedWeeks
                if (data.Cnp != null)
                {
                    Assert.True(res.Cnp.WeeklyResults.Count() > 0);
                    res.Cnp.WeeklyResults.Where(x => x.IsSelected == true).Count()
                    .Should().Be(expectedOutputList[i].Cnp.WeeklyResults.Where(x => x.IsSelected == true).Count());
                }
                if (data.Nwnp != null && data.Nwnp.Where(x => x.InputSource == InputSource.Rp1).Any())
                {
                    Assert.True(res.Nwnp.rp1Results.WeeklyResult.Count() > 0);
                    res.Nwnp.rp1Results.WeeklyResult.Where(x => x.IsSelected == true).Count()
                    .Should().Be(actualOutputList[i].Nwnp.rp1Results.WeeklyResult.Where(x => x.IsSelected == true).Count());
                }
                if (data.Nwnp != null && data.Nwnp.Where(x => x.InputSource == InputSource.Rp14a).Any())
                {
                    Assert.True(res.Nwnp.rp14aResults.WeeklyResult.Count() > 0);
                    res.Nwnp.rp14aResults.WeeklyResult.Where(x => x.IsSelected == true).Count()
                    .Should().Be(expectedOutputList[i].Nwnp.rp14aResults.WeeklyResult.Where(x => x.IsSelected == true).Count());
                }
                i++;
            }
        }
Пример #6
0
        public async Task PostAsync_FailsWithBadRequest_WhenThereIsAValidationError(NoticePayCompositeCalculationRequestModel request, string expectedErrorMessage)
        {
            //Arrange
            var controller = new NoticeController(_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> >()
                                   ));
        }
Пример #7
0
        public async Task <IActionResult> PostAsync([FromBody] NoticePayCompositeCalculationRequestModel data)
        {
            try
            {
                if (data == null)
                {
                    ModelState.AddModelError("",
                                             "Bad payload provided; unable to parse the request , please review request data and try again");

                    _logger.LogError(400, $"Bad payload " +
                                     $"{ModelState}\n Request Data is null and could not be parsed");
                    return(BadRequest(ModelState));
                }

                var validator = new NoticePayCompositeCalculationRequestValidator();
                if (!ModelState.IsValid || !validator.Validate(data).IsValid)
                {
                    _logger.LogError((int)System.Net.HttpStatusCode.BadRequest, $"Request model not valid " +
                                     $"{ModelState}\n Request Data {JsonConvert.SerializeObject(data)} \n Errors : " +
                                     $"{validator.Validate(data).Errors.GetErrorsAsString()} ");
                    return(BadRequest(ModelState));
                }

                var result = await _service.PerformNoticePayCompositeCalculationAsync(data, _options);

                _logger.LogInformation((int)HttpStatusCode.OK,
                                       $"Calculation performed successfully for the request data provided \n Request Data: {JsonConvert.SerializeObject(data)}");
                return(Ok(result));
            }
            catch (MissingConfigurationException exp)
            {
                _logger.LogError((int)HttpStatusCode.BadRequest,
                                 $"Calculation was not performed for the request data provided \n Request Data: {JsonConvert.SerializeObject(data)} Bad payload provided; {exp.Message}, please review request data and try again");
                return(BadRequest($"Bad payload provided; {exp.Message}, please review request data and try again"));
            }
        }
Пример #8
0
        public async Task <NoticePayCompositeCalculationResponseDTO> PerformNoticePayCompositeCalculationAsync(NoticePayCompositeCalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            var result        = new NoticePayCompositeCalculationResponseDTO();
            var cnpOutput     = new CompensatoryNoticePayCalculationResponseDTO();
            var nwnpOutput    = new NoticeWorkedNotPaidCompositeOutput();
            var rp1TraceInfo  = new TraceInfo();
            var rp14TraceInfo = new TraceInfo();

            //CNP calculation
            if (data.Cnp != null)
            {
                cnpOutput = await _cnpService.PerformCompensatoryNoticePayCalculationAsync(data.Cnp, options);

                cnpOutput.WeeklyResults.ForEach(x => x.IsSelected = true);
            }

            //NWNP calculation
            if (data.Nwnp != null && data.Nwnp.Any())
            {
                var statutoryMax = ConfigValueLookupHelper.GetStatutoryMax(options, data.Nwnp.FirstOrDefault().InsolvencyDate);

                foreach (var nwnp in data.Nwnp)
                {
                    var traceDate = new TraceInfoDate();
                    var res       = await _nwnpService.PerformNwnpCalculationAsync(nwnp, options, traceDate);

                    if (res.InputSource == InputSource.Rp1)
                    {
                        //nwnpOutput.nwnpResults.rP1ResultsList.Add(res);
                        nwnpOutput.rp1Results.WeeklyResult.AddRange(res.WeeklyResult);
                        rp1TraceInfo.Dates.Add(traceDate);
                        rp1TraceInfo.NumberOfDays = 0.00m;
                        foreach (var week in res.WeeklyResult)
                        {
                            rp1TraceInfo.NumberOfDays += week.EmploymentDays;
                        }
                    }
                    else if (res.InputSource == InputSource.Rp14a)
                    {
                        //nwnpOutput.nwnpResults.rP14aResultsList.Add(res);
                        nwnpOutput.rp14aResults.WeeklyResult.AddRange(res.WeeklyResult);
                        rp14TraceInfo.Dates.Add(traceDate);
                        rp14TraceInfo.NumberOfDays = 0.00m;
                        foreach (var week in res.WeeklyResult)
                        {
                            rp14TraceInfo.NumberOfDays += week.EmploymentDays;
                        }
                    }
                }

                var rp1Total   = 0m;
                var rp14aTotal = 0m;

                //merge pay weeks
                nwnpOutput.rp1Results = await nwnpOutput.rp1Results.MergePayWeeks(options);

                nwnpOutput.rp1Results.InputSource  = InputSource.Rp1;
                nwnpOutput.rp1Results.StatutoryMax = statutoryMax;
                rp1Total = nwnpOutput.rp1Results.WeeklyResult.Sum(x => x.NetEntitlement);

                //merge pay weeks
                nwnpOutput.rp14aResults = await nwnpOutput.rp14aResults.MergePayWeeks(options);

                nwnpOutput.rp14aResults.InputSource  = InputSource.Rp14a;
                nwnpOutput.rp14aResults.StatutoryMax = statutoryMax;
                rp14aTotal = nwnpOutput.rp14aResults.WeeklyResult.Sum(x => x.NetEntitlement);

                //select the input source
                // Choose RP1 list or RP14a list with the lowest total NetEntitlement
                if ((rp1Total < rp14aTotal && rp14aTotal != 0 && rp1Total != 0) || (rp1Total > 0 && rp14aTotal == 0))
                {
                    nwnpOutput.SelectedInputSource = InputSource.Rp1;
                    nwnpOutput.rp1Results.WeeklyResult.ForEach(x => x.IsSelected   = true);
                    nwnpOutput.rp14aResults.WeeklyResult.ForEach(x => x.IsSelected = false);
                    nwnpOutput.TraceInfo = await rp1TraceInfo.ConvertToJson();
                }
                else
                {
                    nwnpOutput.SelectedInputSource = InputSource.Rp14a;
                    nwnpOutput.rp1Results.WeeklyResult.ForEach(x => x.IsSelected   = false);
                    nwnpOutput.rp14aResults.WeeklyResult.ForEach(x => x.IsSelected = true);
                    nwnpOutput.TraceInfo = await rp14TraceInfo.ConvertToJson();
                }
            }

            result.Cnp  = cnpOutput;
            result.Nwnp = nwnpOutput;
            return(result);
        }