コード例 #1
0
 public AgeController(
     PlanetStore planetStore,
     AgeService ageService,
     IClock clock)
 {
     this._planetStore = planetStore;
     this._ageService  = ageService;
     this._clock       = clock;
 }
コード例 #2
0
            public void WhenIsNotAdult_ThenReturnFalse([Range(0, 20)] int value)
            {
                // Arrange
                var sut = new AgeService();

                // Act
                var result = sut.IsAdult(value);

                // Assert
                result.IsAdult.Should().BeFalse();
            }
コード例 #3
0
            public void WhenIsAdult_ThenReturnTrue()
            {
                // Arrange
                var sut = new AgeService();
                //var value = _fixture.Create<int>() + 21;

                // Act
                var result = sut.IsAdult(21);

                // Assert
                result.IsAdult.Should().BeTrue();
            }
コード例 #4
0
            public void WhenAgeIsNegative_ThenThrowArgumentException()
            {
                // Arrange
                var sut   = new AgeService();
                var value = _fixture.Create <int>() * -1;

                // Act
                Action action = () => sut.IsAdult(value);

                // Assert
                action.Should().Throw <ArgumentException>();
            }
コード例 #5
0
        /// <summary>
        /// Implements the oldest driver over 75 rule.
        /// </summary>
        /// <param name="policy"></param>
        public Result ImplementRule(Policy policy)
        {
            var oldestDriverOnPolicy = AgeService.GetOldestDriver(policy.DriversOnPolicy);
            var age = AgeService.GetAge(oldestDriverOnPolicy.DateOfBirth, policy.PolicyStartDate);

            if (age > MaxAge)
            {
                return(new Result($"Age of Oldest Driver {oldestDriverOnPolicy.Name}", false));
            }
            else
            {
                return(new Result(string.Empty, true));
            }
        }
コード例 #6
0
        /// <summary>
        /// If the youngest driver is under the age of 21 at the start date of the policy decline with a message
        /// "Age of Youngest Driver" and append the name of the driver.
        /// </summary>
        /// <param name="policy"></param>
        /// <returns></returns>
        public Result ImplementRule(Policy policy)
        {
            //get youngest driver and age
            var youngestDriverOnPolicy = AgeService.GetYoungestDriver(policy.DriversOnPolicy);
            var age = AgeService.GetAge(youngestDriverOnPolicy.DateOfBirth, policy.PolicyStartDate);

            if (age >= 21)
            {
                return(new Result(string.Empty, true));
            }
            else
            {
                return(new Result("Age of Youngest Driver - " + youngestDriverOnPolicy.Name, false));
            }
        }
コード例 #7
0
        /// <summary>
        ///If the youngest driver is aged between 21 and 25 at the start date of the policy increase the premium by 20%.
        ///If the youngest driver is aged between 26 and 75 at the start date of the policy decrease the premium by 10%.
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="premium"></param>
        /// <returns></returns>
        public decimal ImplementRule(Policy policy, decimal premium)
        {
            var youngestDriver    = AgeService.GetYoungestDriver(policy.DriversOnPolicy);
            var youngestDriverAge = AgeService.GetAge(youngestDriver.DateOfBirth, policy.PolicyStartDate);


            if (youngestDriverAge >= 21 && youngestDriverAge <= 25)
            {
                premium += premium * 0.2m;
            }
            else if (youngestDriverAge >= 26 && youngestDriverAge <= 75)
            {
                premium += premium * 0.1m;
            }

            return(premium);
        }
コード例 #8
0
        /// <summary>
        ///For each claim within 1 year of the start date of the policy increase the premium by 20%.
        ///For each claim within 2 - 5 years of the start date of the policy increase the premium by 10%.
        ///
        /// </summary>
        /// <param name="policy"></param>
        /// <param name="premium"></param>
        /// <returns></returns>
        public decimal ImplementRule(Policy policy, decimal premium)
        {
            foreach (var driver in policy.DriversOnPolicy)
            {
                foreach (var claim in driver.ClaimsAssociatedToDriver)
                {
                    int age = AgeService.GetAge(claim.DateOfClaim, policy.PolicyStartDate);

                    if (age <= 1)
                    {
                        premium = premium + premium * 0.2M;
                    }
                    else if (age >= 2 && age <= 5)
                    {
                        premium += premium * 0.1M;
                    }
                }
            }

            return(premium);
        }
コード例 #9
0
 public DataBaseCommands(DataBaseHandlingService db, AgeService age, CompanyService cs)
 {
     DataBaseHandlingService = db;
     AgeService     = age;
     CompanyService = cs;
 }
コード例 #10
0
 public int ExampleNoArgsWithService(AgeService ageService)
 {
     // we returning a scalar, you do not require the Expression<>
     // AgeService registered in DI. Use it here
     return(ageService.Calc(new Person()));
 }