public bool AddRefuling(NewRefulingVm model, NewCarHistoryVm carHistoryVm) { if (model is null) { return(false); } else { var refuelingModelToAdd = _mapper.Map <Refueling>(model); var carHistoryModelToAdd = _mapper.Map <CarHistory>(carHistoryVm); refuelingModelToAdd.IsActive = true; refuelingModelToAdd.BurningFuelPerOneHundredKilometers = VehicleServiceHelpers.ReturnBurningPerOneHoundredKilometers(model); refuelingModelToAdd.FuelPrice = decimal.Multiply(refuelingModelToAdd.AmountOfFuel, refuelingModelToAdd.PriceForOneUnit); string userId = GetUserIdByVehicleId(refuelingModelToAdd.VehicleId); bool refuelingSucessfullyAdded = _vehicleRepository.AddRefueling(refuelingModelToAdd, userId, carHistoryModelToAdd); if (refuelingSucessfullyAdded == true) { return(true); } else { return(false); } } }
public void ShouldBeReturnBurnigFuelPerOneHounderKilometers() { //Arrange //Correct data var firstModel = new NewRefulingVm() { LastMeters = 100, MeterStatus = 550, AmountOfFuel = 30, IsRefulingFull = true }; //Kilometers before refueling is greather than actually meter status var secondModel = new NewRefulingVm() { LastMeters = 1200, MeterStatus = 1190, IsRefulingFull = true }; //Kilometers before refueling is equal with actually meter status var thirdModel = new NewRefulingVm() { LastMeters = 1200, MeterStatus = 1200, IsRefulingFull = true }; var fourthModel = new NewRefulingVm() { LastMeters = 1200, MeterStatus = 1390, IsRefulingFull = true }; //Act decimal burningFuelPerOneHoundredKilometersIsRefuelingFullTrue = VehicleServiceHelpers .ReturnBurningPerOneHoundredKilometers(firstModel); decimal burningFuelPerOneHoundredKilometersIsRefuelingFullFalse = VehicleServiceHelpers .ReturnBurningPerOneHoundredKilometers(secondModel); decimal burningFuelPerOneHoundredKilometersIsRefuelingAfterRefuelingIsLessThanBefore = VehicleServiceHelpers .ReturnBurningPerOneHoundredKilometers(thirdModel); decimal burningFuelPerOneHoundredKilometersIsRefuelingAfterRefuelingIsEqualThanBefore = VehicleServiceHelpers .ReturnBurningPerOneHoundredKilometers(fourthModel); //Assert burningFuelPerOneHoundredKilometersIsRefuelingFullTrue.Should().Be(6.6667M); burningFuelPerOneHoundredKilometersIsRefuelingFullTrue.Should().BePositive(); burningFuelPerOneHoundredKilometersIsRefuelingFullTrue.Should().NotBe(0M); burningFuelPerOneHoundredKilometersIsRefuelingFullFalse.Should().Be(0M); burningFuelPerOneHoundredKilometersIsRefuelingAfterRefuelingIsLessThanBefore.Should().Be(0); burningFuelPerOneHoundredKilometersIsRefuelingAfterRefuelingIsEqualThanBefore.Should().Be(0); }
public bool EditRefueling(NewRefulingVm refueling) { if (refueling is null) { return(false); } var refuelingForUpdate = _mapper.Map <Refueling>(refueling); refuelingForUpdate.BurningFuelPerOneHundredKilometers = VehicleServiceHelpers.ReturnBurningPerOneHoundredKilometers(refueling); refuelingForUpdate.FuelPrice = decimal.Multiply(refuelingForUpdate.AmountOfFuel, refuelingForUpdate.PriceForOneUnit); refuelingForUpdate.ModifiedDateTime = DateTime.UtcNow; bool isCorrectEdit = _vehicleRepository.EditRefueling(refuelingForUpdate); if (isCorrectEdit == true) { return(true); } else { return(false); } }