Beispiel #1
0
        public void GetDetails_Test()
        {
            //Arrange
            IInsuranceService service = InsuranceFactory.GetInsuranceObj();
            int     age      = 25;
            double  sum      = 50000;
            Details expected = new Details();

            expected.Age               = age;
            expected.Sum               = sum;
            expected.RiskPremium       = 0.82;
            expected.RenewalCommision  = 0.02;
            expected.NetPremium        = 0.84;
            expected.InitialCommission = 1.72;
            expected.GrossPremium      = 2.56;
            expected.Notes             = "Successfully return a premium";
            Details actual = new Details();

            actual.Age = age;
            actual.Sum = sum;

            //Act
            actual = service.GetDetails(actual);

            //Assert
            Assert.AreEqual(expected.RiskPremium, actual.RiskPremium);
            Assert.AreEqual(expected.GrossPremium, actual.GrossPremium);
        }
Beispiel #2
0
        public void GetDetails_InvalidSum()
        {
            //Arrange
            IInsuranceService service  = InsuranceFactory.GetInsuranceObj();
            string            expected = "Unable to provide premium";
            Details           actual   = new Details();

            actual.Age = 62;
            actual.Sum = 350000;

            //Act
            actual = service.GetDetails(actual);

            //Assert
            Assert.AreEqual(expected, actual.Notes);
        }
Beispiel #3
0
        public void GetDetails_InvalidAge()
        {
            //Arrange
            IInsuranceService service  = InsuranceFactory.GetInsuranceObj();
            string            expected = "Invalid Age. Age Range is 18 - 65";
            Details           actual   = new Details();

            actual.Age = 16;
            actual.Sum = 25000;

            //Act
            actual = service.GetDetails(actual);

            //Assert
            Assert.AreEqual(expected, actual.Notes);
        }
Beispiel #4
0
        public IHttpActionResult GetInsurance([FromBody] Details details)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                IInsuranceService insuranceService = InsuranceFactory.GetInsuranceObj();
                details = insuranceService.GetDetails(details);
                return(Ok(details));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }