public void GetPreferentialLimit_ThrowsException_WhenNoConfigForDate()
        {
            var date = new DateTime(1899, 1, 1);

            //Act
            Exception ex = Assert.Throws <MissingConfigurationException>(() => ConfigValueLookupHelper.GetPreferentialLimit(_configOptions, date));
        }
Esempio n. 2
0
        public async Task <ApportionmentCalculationResponseDTO> PerformApportionmentCalculationAsync(
            ApportionmentCalculationRequestModel data, IOptions <ConfigLookupRoot> options)
        {
            decimal preferentialClaim       = 0.0m;
            decimal preferentialLimit       = ConfigValueLookupHelper.GetPreferentialLimit(options, DateTime.Now);
            decimal apportionmentPercentage = 1.0m;

            if (data.TupeStatus)
            {
                preferentialClaim = Math.Min(data.GrossPaidInFourMonth, preferentialLimit);
            }
            if (data.TupeStatus == false && data.TotalClaimedInFourMonth > 0.0m)
            {
                apportionmentPercentage = (data.TotalClaimedInFourMonth <= preferentialLimit) ? 1m :
                                          data.GrossPaidInFourMonth / data.TotalClaimedInFourMonth;

                preferentialClaim = (data.TotalClaimedInFourMonth > preferentialLimit
                    ? preferentialLimit * apportionmentPercentage
                    : data.GrossPaidInFourMonth * apportionmentPercentage);
            }
            apportionmentPercentage = Math.Round(apportionmentPercentage * 100, 4);
            var result = new ApportionmentCalculationResponseDTO()
            {
                ApportionmentPercentage = apportionmentPercentage,
                PrefClaim    = Math.Round(preferentialClaim, 2),
                NonPrefClaim = Math.Round((data.GrossEntitlement - preferentialClaim), 2),
                TupeStatus   = data.TupeStatus
            };

            return(await Task.FromResult(result));
        }
        public void GetPreferentialLimit_Returns_CorrectPreferentialLimit_ForGiven_date(
            DateTime someDate, decimal expectedPreferntialLimit)
        {
            //Arrange
            //Act
            var result = ConfigValueLookupHelper.GetPreferentialLimit(_configOptions, someDate);

            //Assert
            result.Should().Be(expectedPreferntialLimit);
        }
        public async Task ReturnsCorrectPrefAndNonPrefClaimValues_WhenTupeAndExceedsLimit()
        {
            // Arrange
            var request = new ApportionmentCalculationRequestModel()
            {
                GrossPaidInFourMonth    = 898.00m,
                GrossEntitlement        = 1002.24m,
                TotalClaimedInFourMonth = 4698.00m,
                TupeStatus = true
            };

            // Act
            var result = await _service.PerformApportionmentCalculationAsync(request, _options);

            // Assert
            Math.Round(result.PrefClaim, 2).Should()
            .Be(ConfigValueLookupHelper.GetPreferentialLimit(_options, DateTime.Now));
            Math.Round(result.NonPrefClaim, 2).Should()
            .Be(Math.Round(request.GrossEntitlement, 2) - Math.Round(result.PrefClaim, 2));
            result.TupeStatus.Should().Be(request.TupeStatus);
            result.ApportionmentPercentage.Should().Be(100.0m);
        }