public VehicleBLL(IMapper mapper, IVehicleDAL vehicleDAL, VehicleValidation vehicleValidation)
     : base(vehicleDAL)
 {
     _mapper            = mapper;
     _vehicleDAL        = vehicleDAL;
     _vehicleValidation = vehicleValidation;
 }
        public void VehicleYearValidation_ValidYears_ExpectedSuccess(int testValue)
        {
            // Arrange
            bool result = true;

            // Act
            result = VehicleValidation.VehicleYearValidation(testValue);

            // Assert
            Assert.True(result);
        }
        public void VehicleYearValidation_InvalidYears_ExpectedFail(int testValue)
        {
            // Arrange
            bool result = true;

            // Act
            result = VehicleValidation.VehicleYearValidation(testValue);

            // Assert
            Assert.False(result);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validYear = VehicleValidation.VehicleYearValidation(Year);

            if (validYear == false)
            {
                yield return(new ValidationResult("Enter a valid model year",
                                                  new[] { nameof(Year) }));
            }

            yield return(ValidationResult.Success);
        }
Esempio n. 5
0
        public string TaskExecute(ICommand command)
        {
            if (command.Name != "SetupPark" && this.VehiclePark == null)
            {
                return("The vehicle park has not been set up");
            }

            // TODO this switch can be replaced by strategy pattern in the future
            switch (command.Name)
            {
            case "SetupPark":
                this.VehiclePark = new VehiclePark(Convert.ToInt32(command.Parameters["sectors"]), Convert.ToInt32(command.Parameters["placesPerSector"]));
                return("Vehicle park created");

            case "Park":
                var vehicleValidation = new VehicleValidation();
                switch (command.Parameters["type"])
                {
                case "car":
                    var car = new Car
                    {
                        LicensePlate  = command.Parameters["licensePlate"],
                        Owner         = command.Parameters["owner"],
                        ReservedHours = int.Parse(command.Parameters["hours"])
                    };
                    vehicleValidation.Validate(car);
                    return(this.VehiclePark.InsertCar(
                               car,
                               int.Parse(command.Parameters["sector"]),
                               int.Parse(command.Parameters["place"]),
                               DateTime.Parse(
                                   command.Parameters["time"],
                                   null,
                                   System.Globalization.DateTimeStyles.RoundtripKind)));

                case "motorbike":
                    var motorbike = new Motorbike
                    {
                        LicensePlate  = command.Parameters["licensePlate"],
                        Owner         = command.Parameters["owner"],
                        ReservedHours = int.Parse(command.Parameters["hours"])
                    };
                    vehicleValidation.Validate(motorbike);
                    return(this.VehiclePark.InsertMotorbike(
                               motorbike,
                               int.Parse(command.Parameters["sector"]),
                               int.Parse(command.Parameters["place"]),
                               DateTime.Parse(
                                   command.Parameters["time"],
                                   null,
                                   System.Globalization.DateTimeStyles.RoundtripKind)));

                case "truck":
                    var truck = new Truck()
                    {
                        LicensePlate  = command.Parameters["licensePlate"],
                        Owner         = command.Parameters["owner"],
                        ReservedHours = int.Parse(command.Parameters["hours"])
                    };
                    vehicleValidation.Validate(truck);
                    return(this.VehiclePark.InsertTruck(
                               truck,
                               int.Parse(command.Parameters["sector"]),
                               int.Parse(command.Parameters["place"]),
                               DateTime.Parse(
                                   command.Parameters["time"],
                                   null,
                                   System.Globalization.DateTimeStyles.RoundtripKind)));

                default:
                    return("Invalid parameter.");
                }

            case "Exit":
                return(this.VehiclePark.ExitVehicle(
                           command.Parameters["licensePlate"],
                           DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind),
                           decimal.Parse(command.Parameters["paid"])));

            case "Status":
                return(this.VehiclePark.GetStatus());

            case "FindVehicle":
                return(this.VehiclePark.FindVehicle(command.Parameters["licensePlate"]));

            case "VehiclesByOwner":
                return(this.VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]));

            default:
                return("Invalid command.");
            }
        }