public RejectionMessageAndSuccess Transform([NotNull] IEnumerable <IDriver> drivers) { if (drivers == null) { throw new ArgumentNullException(nameof(drivers)); } var driversArray = drivers.ToArray(); if (!driversArray.Any()) { return(new RejectionMessageAndSuccess(string.Empty, true)); } var oldestDriver = driversArray.OrderBy(o => o.DateOfBirth).First(); var oldestDriverIsOlderThanMaximumAge = oldestDriver.DateOfBirth < _todayProvider.Get().AddYears(-_maximumAge); if (oldestDriverIsOlderThanMaximumAge) { return(new RejectionMessageAndSuccess($"Age of Oldest Driver {oldestDriver.Name}", false)); } return(new RejectionMessageAndSuccess(string.Empty, true)); }
public RejectionMessageAndSuccess Transform(DateTime policyStartDate) { var today = _todayProvider.Get(); if (today > policyStartDate) { return(new RejectionMessageAndSuccess("Start Date of Policy", false)); } return(new RejectionMessageAndSuccess(string.Empty, true)); }
public RejectionMessageAndSuccess Transform([NotNull] IEnumerable<IDriver> drivers) { if (drivers == null) throw new ArgumentNullException(nameof(drivers)); var driversArray = drivers.ToArray(); if(!driversArray.Any()) return new RejectionMessageAndSuccess(string.Empty, true); var youngestDriver = driversArray.OrderByDescending(o => o.DateOfBirth).First(); var youngestDriverIsOlderThanMinimumAge = youngestDriver.DateOfBirth <= _todayProvider.Get().AddYears(-_minimumAge); if(!youngestDriverIsOlderThanMinimumAge) return new RejectionMessageAndSuccess($"Age of Youngest Driver {youngestDriver.Name}", false); return new RejectionMessageAndSuccess(string.Empty, true); }
public double Transform([NotNull] DriverAndPremium driverAndPremium) { if (driverAndPremium == null) { throw new ArgumentNullException(nameof(driverAndPremium)); } var driver = driverAndPremium.Driver; var premium = driverAndPremium.Premium; var today = _todayProvider.Get(); if (driver.DateOfBirth < today.AddYears(-_startingAdultAge) && driver.DateOfBirth > today.AddYears(-_endingAdultAge)) { premium -= premium * _decreasePremiumValue; } return(premium); }
public double Transform([NotNull] DriverAndPremium driverAndPremium) { if (driverAndPremium == null) { throw new ArgumentNullException(nameof(driverAndPremium)); } var driver = driverAndPremium.Driver; var premium = driverAndPremium.Premium; var today = _todayProvider.Get(); var claimsWithinSmallerTimeFrame = driver.Claims.Where(a => a.DateOfClaim > today.AddYears(-_smallerTimeSpanInYears)); var claimsWithinLargerTimeFrame = driver.Claims.Where(a => a.DateOfClaim <today.AddYears(-_smallerTimeSpanInYears) && a.DateOfClaim> today.AddYears(-_largerTimeSpanInYears)); premium = claimsWithinSmallerTimeFrame.Aggregate(premium, (o, a) => o + o * _largePercentageIncrease); return(claimsWithinLargerTimeFrame.Aggregate(premium, (o, a) => o + o * _smallerPercentIncrease)); }