public void Success_When_TheThereAreFreeParkingSpaces() { _lab08ParkingLotUnitOfWork.Setup(r => r.VehicleRepository.GetAll()).Returns(new List <Vehicle>().AsQueryable()); var vehicle = new RegisterVehicleDTO() { VehicleNumber = It.IsAny <string>(), EntranceTime = It.IsAny <DateTime>(), VehicleCategory = It.IsAny <VehicleCategory>() }; VehicleEntranceResultModel result = _registerService.VehicleEntrance(vehicle); Assert.IsTrue(result.IsSuccessful); }
public void Success_When_TheThereAreEnoughFreeParkingSpacesForVehicleCatC() { var vehiclesInsideTheParkingLot = _fixture.Build <Vehicle>() .With(v => v.VehicleCategory, VehicleCategory.C) .CreateMany(49) .ToList(); _lab08ParkingLotUnitOfWork.Setup(r => r.VehicleRepository.GetAll()).Returns(vehiclesInsideTheParkingLot.AsQueryable()); RegisterVehicleDTO vehicle = _fixture.Build <RegisterVehicleDTO>() .With(v => v.VehicleCategory, VehicleCategory.C) .Create(); VehicleEntranceResultModel result = _registerService.VehicleEntrance(vehicle); Assert.IsTrue(result.IsSuccessful); }
public void Fail_When_TheParkingIsFull() { var vehiclesInsideTheParkingLot = _fixture.Build <Vehicle>() .With(v => v.VehicleCategory, VehicleCategory.C) .CreateMany(50) .ToList(); _lab08ParkingLotUnitOfWork.Setup(r => r.VehicleRepository.GetAll()).Returns(vehiclesInsideTheParkingLot.AsQueryable()); RegisterVehicleDTO vehicle = _fixture.Build <RegisterVehicleDTO>() .With(v => v.VehicleCategory, VehicleCategory.B) .Create(); VehicleEntranceResultModel result = _controller.VehicleEntrance(vehicle); Assert.IsFalse(result.IsSuccessful); }
public VehicleEntranceResultModel VehicleEntrance(RegisterVehicleDTO registerVehicleDTO) { int freeSpaces = GetFreeSpaces(); if (freeSpaces < (int)registerVehicleDTO.VehicleCategory) { return(new VehicleEntranceResultModel() { IsSuccessful = false, Message = "There are not enough spaces!" }); } bool vehicleAlreadyRegistered = _lab08ParkingLotUnitOfWork.VehicleRepository.GetAll().Any(v => v.Number == registerVehicleDTO.VehicleNumber); if (vehicleAlreadyRegistered) { return(new VehicleEntranceResultModel() { IsSuccessful = false, Message = "Vehicle is already registered in this parking lot!" }); } _lab08ParkingLotUnitOfWork.VehicleRepository.Insert(new Vehicle() { Number = registerVehicleDTO.VehicleNumber, VehicleCategory = registerVehicleDTO.VehicleCategory, EntryTime = registerVehicleDTO.EntranceTime, DiscountCard = registerVehicleDTO.DiscountCard }); _lab08ParkingLotUnitOfWork.Save(); return(new VehicleEntranceResultModel() { IsSuccessful = true, Message = $"Welcome {registerVehicleDTO.VehicleNumber}, we wish you a nice stay with us!" }); }
public VehicleEntranceResultModel VehicleEntrance(RegisterVehicleDTO registerVehicleDTO) { VehicleEntranceResultModel result = _registerService.VehicleEntrance(registerVehicleDTO); return(result); }