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); }
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); }
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()); }
public void Generate_VehicleIsNull_ReturnsCannotIdentifyErrorMessage() { // arrange string regPlate = "LP64NNV"; int mileage = 18000; _vehicleFinderMock.Setup(x => x.FindByRegPlate(regPlate)); IValuationEngine valuationService = new ValuationEngine(_vehicleFinderMock.Object, _minimumValuation); // act var result = valuationService.Generate(regPlate, mileage); var expectedErrorMessage = "we can't identify the car"; Assert.IsTrue(result.Errors.Contains(expectedErrorMessage)); }
public void Generate_VehicleIsLessThanMinimum_Returns250() { // arrange string regPlate = "MA53JRO"; int mileAge = 200000; var vehicle = GetVehicle(15000, 3); _vehicleFinderMock.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle); IValuationEngine valuationService = new ValuationEngine(_vehicleFinderMock.Object, _minimumValuation); // act var result = valuationService.Generate(regPlate, mileAge); // assert Assert.AreEqual(250, result.PriceOffered); }
public void Generate_VehicleValuation_ReturnsNewPrice() { // arrange string regPlate = "MA53JRO"; int mileage = 100000; var expectedPrice = (decimal)17243.62; var vehicle = GetVehicle(40000, 10); _vehicleFinderMock.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle); IValuationEngine valuationService = new ValuationEngine(_vehicleFinderMock.Object, _minimumValuation); // act var result = valuationService.Generate(regPlate, mileage); // assert Assert.AreEqual(expectedPrice, result.PriceOffered); }
public void Generate_VehicleBaseValueIsNull_ReturnsCannotValueErrorMessage() { // arrange string regPlate = "MA53JRO"; int mileage = 10000; Vehicle vehicle = GetVehicle(null, 10); _vehicleFinderMock.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle); IValuationEngine valuationService = new ValuationEngine(_vehicleFinderMock.Object, _minimumValuation); // act var result = valuationService.Generate(regPlate, mileage); var expectedErrorMessage = "we can't value a car!"; // assert Assert.IsTrue(result.Errors.Contains(expectedErrorMessage)); }
public void Generate_ReturnsPopulatedValuation() { // arrange string regPlate = "MA53JRO"; int mileage = 100000; var vehicle = GetVehicle(40000, 10); _vehicleFinderMock.Setup(x => x.FindByRegPlate(regPlate)).Returns(vehicle); IValuationEngine valuationService = new ValuationEngine(_vehicleFinderMock.Object, _minimumValuation); // 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); }
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); }