public async Task PostAsync_Succeeds_WithNoAPData()
        {
            //Arrange
            var request = new APPACalculationRequestModel
            {
                Ap = new List <ArrearsOfPayCalculationRequestModel>(),
                Pa = new ProtectiveAwardCalculationRequestModel()
                {
                    InsolvencyDate           = new DateTime(2018, 10, 20),
                    EmploymentStartDate      = new DateTime(2016, 4, 6),
                    DismissalDate            = new DateTime(2018, 10, 20),
                    TribunalAwardDate        = new DateTime(2018, 10, 21),
                    ProtectiveAwardStartDate = new DateTime(2018, 10, 22),
                    ProtectiveAwardDays      = 90,
                    PayDay       = 6,
                    WeeklyWage   = 400M,
                    ShiftPattern = new List <string> {
                        "1", "2", "3", "4", "5"
                    }
                }
            };
            var response = new APPACalculationResponseDTO();

            _service.Setup(m => m.PerformCalculationAsync(request, _confOptions)).ReturnsAsync(response);
            var controller = new APPAController(_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 <APPACalculationResponseDTO> PerformCalculationAsync(APPACalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            var allWeeks      = new List <IWeeklyResult>();
            var result        = new APPACalculationResponseDTO();
            var rp1TraceInfo  = new TraceInfo();
            var rp14TraceInfo = new TraceInfo();

            if (data.Ap != null && data.Ap.Any())
            {
                result.Ap = new ArrearsOfPayAggregateOutput();
                result.Ap.RP1ResultsList = await _apService.PerformCalculationAsync(data.Ap, InputSource.Rp1, options, rp1TraceInfo);

                result.Ap.RP14aResultsList = await _apService.PerformCalculationAsync(data.Ap, InputSource.Rp14a, options, rp14TraceInfo);

                var rp1Any = result.Ap.RP1ResultsList != null && result.Ap.RP1ResultsList.WeeklyResult.Any();
                var rp1Sum = rp1Any ? result.Ap.RP1ResultsList.WeeklyResult.Sum(x => x.NetEntitlement) : 0M;

                var rp14aAny = result.Ap.RP14aResultsList != null && result.Ap.RP14aResultsList.WeeklyResult.Any();
                var rp14aSum = rp14aAny ? result.Ap.RP14aResultsList.WeeklyResult.Sum(x => x.NetEntitlement) : 0M;

                if ((rp1Any && rp1Sum == 0) || (rp1Sum > 0 && rp1Sum < rp14aSum) || (rp1Any && !rp14aAny))
                {
                    result.Ap.SelectedInputSource = InputSource.Rp1;
                    allWeeks.AddRange(result.Ap.RP1ResultsList.WeeklyResult);
                    result.Ap.TraceInfo = await rp1TraceInfo.ConvertToJson();
                }
                else
                {
                    result.Ap.SelectedInputSource = InputSource.Rp14a;
                    allWeeks.AddRange(result.Ap.RP14aResultsList.WeeklyResult);
                    result.Ap.TraceInfo = await rp14TraceInfo.ConvertToJson();
                }
            }

            if (data.Pa != null)
            {
                result.Pa = await _paService.PerformProtectiveAwardCalculationAsync(data.Pa, options);

                allWeeks.AddRange(result.Pa.PayLines);
            }

            allWeeks.OrderByDescending(x => x.NetEntitlement)
            .ThenByDescending(x => x.GrossEntitlementIn4Months)
            .Take(8)
            .ToList()
            .ForEach(x => x.IsSelected = true);

            return(result);
        }
        public async Task PostAsync_Succeeds_WithRP14aDataAndRp1NotRequiredOverride()
        {
            //Arrange
            var request = new APPACalculationRequestModel
            {
                Rp1NotRequired   = true,
                Rp14aNotRequired = false,
                Ap = new List <ArrearsOfPayCalculationRequestModel>()
                {
                    new ArrearsOfPayCalculationRequestModel()
                    {
                        InputSource         = InputSource.Rp14a,
                        InsolvencyDate      = new DateTime(2018, 10, 20),
                        EmploymentStartDate = new DateTime(2016, 04, 06),
                        DismissalDate       = new DateTime(2018, 10, 20),
                        DateNoticeGiven     = new DateTime(2018, 10, 6),
                        UnpaidPeriodFrom    = new DateTime(2018, 10, 1),
                        UnpaidPeriodTo      = new DateTime(2018, 10, 9),
                        ApClaimAmount       = 700M,
                        IsTaxable           = true,
                        PayDay       = 6,
                        ShiftPattern = new List <string> {
                            "1", "2", "3", "4", "5"
                        },
                        WeeklyWage = 400m
                    },
                    new ArrearsOfPayCalculationRequestModel()
                    {
                        InputSource         = InputSource.Rp14a,
                        InsolvencyDate      = new DateTime(2018, 10, 20),
                        EmploymentStartDate = new DateTime(2016, 04, 06),
                        DismissalDate       = new DateTime(2018, 10, 20),
                        DateNoticeGiven     = new DateTime(2018, 10, 14),
                        UnpaidPeriodFrom    = new DateTime(2018, 10, 10),
                        UnpaidPeriodTo      = new DateTime(2018, 10, 18),
                        ApClaimAmount       = 600M,
                        IsTaxable           = true,
                        PayDay       = 6,
                        ShiftPattern = new List <string> {
                            "1", "2", "3", "4", "5"
                        },
                        WeeklyWage = 400m
                    }
                },
                Pa = new ProtectiveAwardCalculationRequestModel()
                {
                    InsolvencyDate           = new DateTime(2018, 10, 20),
                    EmploymentStartDate      = new DateTime(2016, 4, 6),
                    DismissalDate            = new DateTime(2018, 10, 20),
                    TribunalAwardDate        = new DateTime(2018, 10, 21),
                    ProtectiveAwardStartDate = new DateTime(2018, 10, 22),
                    ProtectiveAwardDays      = 90,
                    PayDay       = 6,
                    WeeklyWage   = 400M,
                    ShiftPattern = new List <string> {
                        "1", "2", "3", "4", "5"
                    }
                }
            };
            var response = new APPACalculationResponseDTO();

            _service.Setup(m => m.PerformCalculationAsync(request, _confOptions)).ReturnsAsync(response);
            var controller = new APPAController(_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);
        }