Exemplo n.º 1
0
        public void Generate_ReducesValuation_BasedOnMileage()
        {
            // arrange
            string  regPlate                    = "MA53JRO";
            int     mileage                     = 10000;
            decimal expectedValue               = 17952.11M;
            var     ageEvaluationCalculator     = new AgeEvaluationCalculator(GetAgeEvaluationStrategies());
            var     mileageEvaluationCalculator = new MileageEvaluationCalculator(GetMileageStrategies());

            Vehicle vehicle = new Vehicle()
            {
                AgeInYears    = 10,
                BaseValuation = 30000,
                Derivative    = "ZETEC",
                Manufacturer  = "FORD",
                Model         = "FIESTA",
                RegPlate      = "MA53JRO"
            };

            Mock <IVehicleFinder> vehicleFinder = new Mock <IVehicleFinder>();

            vehicleFinder.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle);

            IValuationEngine valuationService = new ValuationEngine(vehicleFinder.Object,
                                                                    ageEvaluationCalculator,
                                                                    mileageEvaluationCalculator);

            // act
            var result = valuationService.Generate(regPlate, mileage);

            // assert
            Assert.AreEqual(expectedValue, result.PriceOffered);
        }
Exemplo n.º 2
0
        public void When_Generate_Called_And_Evaluation_ForVehicle_Becomes_Negative_Then_It_Should_Return_MinimumEvaluationValue()
        {
            // arrange
            string  regPlate = "MA53JRO";
            int     mileage  = 10000;
            var     ageEvaluationCalculator     = new AgeEvaluationCalculator(GetAgeEvaluationStrategies());
            var     mileageEvaluationCalculator = new MileageEvaluationCalculator(GetMileageStrategies());
            Vehicle vehicle = new Vehicle()
            {
                AgeInYears    = 30,
                BaseValuation = 10,
                Derivative    = "ZETEC",
                Manufacturer  = "FORD",
                Model         = "FIESTA",
                RegPlate      = "MA53JRO"
            };

            var expectedValue = 250.0m;

            Mock <IVehicleFinder> vehicleFinder = new Mock <IVehicleFinder>();

            vehicleFinder.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle);

            IValuationEngine valuationService = new ValuationEngine(vehicleFinder.Object,
                                                                    ageEvaluationCalculator,
                                                                    mileageEvaluationCalculator);

            // act
            var result = valuationService.Generate(regPlate, mileage);

            // assert
            Assert.AreEqual(expectedValue, result.PriceOffered);
        }
Exemplo n.º 3
0
        public void When_Generate_Called_With_NullBaseValue_ForVehicle_Should_Return_UnableToEvaluate()
        {
            // arrange
            string  regPlate = "MA53JRO";
            int     mileage  = 10000;
            var     ageEvaluationCalculator     = new AgeEvaluationCalculator(GetAgeEvaluationStrategies());
            var     mileageEvaluationCalculator = new MileageEvaluationCalculator(GetMileageStrategies());
            Vehicle vehicle = new Vehicle()
            {
                AgeInYears    = 10,
                BaseValuation = null,
            };

            var expectedValue = ErrorTypes.UnableToEvaluate;

            Mock <IVehicleFinder> vehicleFinder = new Mock <IVehicleFinder>();

            vehicleFinder.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle);

            IValuationEngine valuationService = new ValuationEngine(vehicleFinder.Object,
                                                                    ageEvaluationCalculator,
                                                                    mileageEvaluationCalculator);

            // act
            var result = valuationService.Generate(regPlate, mileage);

            // assert
            Assert.AreEqual(expectedValue, result.Errors.First());
        }
Exemplo n.º 4
0
        public void When_CalculatePriceReductionByMileage_Called_For_OldVehicle_Then_Result_ShouldBe_Expected()
        {
            // arrange
            var expected = 50.0m;
            var mileage  = 50000;
            var strategy = new MileageEvaluationCalculator(GetStrategies());

            Vehicle vehicle = new Vehicle()
            {
                AgeInYears    = 10,
                BaseValuation = 50000,
                Derivative    = "ZETEC",
                Manufacturer  = "FORD",
                Model         = "FIESTA",
                RegPlate      = "MA53JRO"
            };

            // act
            var result = strategy.CalculatePriceReductionByMileage(vehicle, mileage);

            // assert
            Assert.AreEqual(expected, result);
        }
Exemplo n.º 5
0
        public void Generate_ReturnsPopulatedValuation()
        {
            // arrange
            string regPlate = "MA53JRO";
            int    mileage  = 10000;
            var    ageEvaluationCalculator     = new AgeEvaluationCalculator(GetAgeEvaluationStrategies());
            var    mileageEvaluationCalculator = new MileageEvaluationCalculator(GetMileageStrategies());

            Vehicle vehicle = new Vehicle()
            {
                AgeInYears    = 10,
                BaseValuation = 40000,
                Derivative    = "ZETEC",
                Manufacturer  = "FORD",
                Model         = "FIESTA",
                RegPlate      = "MA53JRO"
            };

            Mock <IVehicleFinder> vehicleFinder = new Mock <IVehicleFinder>();

            vehicleFinder.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle);

            IValuationEngine valuationService = new ValuationEngine(vehicleFinder.Object,
                                                                    ageEvaluationCalculator,
                                                                    mileageEvaluationCalculator);

            // act
            var result = valuationService.Generate(regPlate, mileage);

            // assert
            Assert.IsInstanceOfType(result, typeof(Valuation));

            Assert.AreEqual(mileage, result.Mileage);
            Assert.AreEqual(regPlate, result.RegPlate);
            Assert.IsNotNull(result.AgeInYears);
            Assert.IsNotNull(result.PriceOffered);
        }