Esempio n. 1
0
        public void CalculateMonthlyPremium_Throw_When_Age_Is_Greater_Than_150()
        {
            CalculatorParameter calculatorParameter = new CalculatorParameter {
                Age = 151, DeathSumInsured = 10000
            };

            var ex = Assert.Throws <BusinessException>(() => _calculatorService.CalculateMonthlyPremium(calculatorParameter));

            Assert.IsTrue(Constants.CALCULATOR_PARAMETER_AGE_RANGE_ERROR == ex.Message, "CalculateMonthlyPremium_Throw_When_Age_Is_Greater_Than_150 success");
        }
Esempio n. 2
0
        public void CalculateMonthlyPremium_Throw_When_DeathSumInsured_Is_0()
        {
            CalculatorParameter calculatorParameter = new CalculatorParameter {
                DeathSumInsured = 0
            };

            var ex = Assert.Throws <BusinessException>(() => _calculatorService.CalculateMonthlyPremium(calculatorParameter));

            Assert.IsTrue(Constants.CALCULATOR_PARAMETER_DEATH_SUM_INSURED_NULL_ERROR == ex.Message, "CalculateMonthlyPremium_Throw_When_DeathSumInsured_Is_0 success");
        }
Esempio n. 3
0
        public decimal?CalculateMonthlyPremium(CalculatorParameter calculatorParameter)
        {
            decimal?premium = null;

            #region Business validations
            if (calculatorParameter == null)
            {
                throw new BusinessException(Constants.CALCULATOR_PARAMETER_NULL_ERROR);
            }

            if (calculatorParameter.DeathSumInsured <= 0)
            {
                throw new BusinessException(Constants.CALCULATOR_PARAMETER_DEATH_SUM_INSURED_NULL_ERROR);
            }

            if (calculatorParameter.Age <= 0)
            {
                throw new BusinessException(Constants.CALCULATOR_PARAMETER_AGE_NULL_ERROR);
            }

            if (calculatorParameter.Age > 150)
            {
                throw new BusinessException(Constants.CALCULATOR_PARAMETER_AGE_RANGE_ERROR);
            }
            #endregion

            // Get occupation details
            Occupation occupation = _occupationService.GetOccupationByID(calculatorParameter.OccupationID);

            premium = Math.Round(calculatorParameter.DeathSumInsured * occupation.RatingDetail.Factor * calculatorParameter.Age / 1000, 2);

            // If unable to calculate premium for given parameters
            if (!premium.HasValue)
            {
                throw new Exception(Constants.PREMIUM_NULL);
            }

            return(premium);
        }
Esempio n. 4
0
        public ActionResult <decimal> Calculate(CalculatorParameter calculatorParameter)
        {
            decimal?monthlyPremium = _calculatorService.CalculateMonthlyPremium(calculatorParameter);

            return(Ok(monthlyPremium));
        }