public PremiumCalculatorControllerUnitTest() { pc1 = new PremiumInfoDTO { age = 10, dateOfBirth = DateTime.Now.AddDays(-100), Factor = 1.50M, sumInsured = 100000 }; pc2 = new PremiumInfoDTO { age = 10, dateOfBirth = DateTime.Now.AddDays(-100), Factor = 1.25M, sumInsured = 100000 }; PremiumInfoList = new List <PremiumInfoDTO>(); PremiumInfoList.Add(pc1); oc1 = new Occupation { factor = 1.10M, occupationName = "Author" }; oc2 = new Occupation { factor = 1.75M, occupationName = "Writer" }; OccupationList = new List <Occupation>(); OccupationList.Add(oc1); OccupationList.Add(oc2); _logger = new LoggerManager(); _repository = new Mock <IRepositoryWrapper>(); ctrl = new PremiumCalculatorController(_logger, _repository.Object); }
public void TestCalculateError() { decimal calculatedPremiumAmount = 0; //Pass invalid values for age, facor, sumInsured to return ZERO premium pc2 = new PremiumInfoDTO { age = 0, dateOfBirth = DateTime.Now.AddDays(-100), Factor = 0.0M, sumInsured = 0 }; calculatedPremiumAmount = ctrl.CalculatePremium(pc2); Assert.IsTrue(calculatedPremiumAmount <= 0, "Premium Amount is not calculated."); }
public decimal CalculatePremium([FromBody] PremiumInfoDTO info) { try { // This logic can be moved to Datbase procedure and call should be thru Repository pattern. return((info.sumInsured * info.Factor * info.age) / 1000 * 12); } catch (Exception ex) { _logger.LogError($"Something went wrong inside GetAllChequePayees action: {ex.Message}"); return(-1); } }