public void TestAddVehicle_ModelNotFoundException()
        {
            Vehicle vehicle = new Vehicle(
                100000, //ModelId
                30,
                "AC34793",
                1230.2,
                true
                );

            Assert.Throws <ModelNotFoundException>(
                () => vehicleDAO.AddVehicle(vehicle)
                );
        }
Exemple #2
0
        public void Execute()
        {
            DAOFactory  daoFactory = DAOFactory.GetFactory(DAOFactory.Type.Postgres);
            IVehicleDAO vehicleDAO = daoFactory.GetVehicleDAO();

            _id = vehicleDAO.AddVehicle(_vehicle);
        }
        public void RegisterVehicle(Vehicle vehicle, Location initialLocation)
        {
            var results = new List <ValidationResult>();

            if (Validator.TryValidateObject(vehicle, new ValidationContext(vehicle), results, validateAllProperties: true))
            {
                // add the vehicle to the data repository
                _dao.AddVehicle(vehicle);
                TransferVehicle(vehicle, initialLocation);
            }
            else
            {
                throw new ValidationException(
                          results
                          .Where(r => r != ValidationResult.Success)
                          .Select(r => r.ErrorMessage ?? "Error")
                          .Aggregate((i, j) => i + Environment.NewLine + j));
            }
        }