public void Test_Builder2()
        {
            Builder2.Builder builder = new Builder2.Builder();
            builder.Register("car", Car.Create);
            builder.Register("moto", Moto.Create);

            CreateVehicle createVehicle = builder.ToFactory();

            IVehicle vehicle1 = createVehicle("car");

            Assert.Equal("Car ", vehicle1.ToString());
            IVehicle vehicle2 = createVehicle("moto");

            Assert.Equal("Moto ", vehicle2.ToString());
        }
Example #2
0
        public void AndVehicleRepositoryThrows_ThenWrapsException()
        {
            _vehicleRepo
            .Setup(v => v.Create(It.IsAny <int>(), It.IsAny <Vehicle>()))
            .Throws <InvalidOperationException>();

            var vehicleForm = new VehicleFormModel {
                Name = "vehicle"
            };

            var handler = new CreateVehicle(_vehicleRepo.Object, _photoRepo.Object);

            var ex = Assert.Throws <BusinessServicesException>(() => handler.Execute(UserId, vehicleForm, null));

            Assert.IsType <InvalidOperationException>(ex.InnerException);
        }
Example #3
0
        public static void Main(string[] args)
        {
            Builder builder = new Builder();

            builder.Register("car", Car.Create);
            builder.Register("moto", Moto.Create);

            CreateVehicle createVehicle = builder.ToFactory();

            IVehicle vehicle1 = createVehicle("car");

            Console.WriteLine(vehicle1);
            IVehicle vehicle2 = createVehicle("moto");

            Console.WriteLine(vehicle2);
        }
Example #4
0
        private static void createTruck(bool i_IsElectric, string i_TruckModel, string i_LicencePlate, VehicleOwner i_VehicleOwner, eVehicles i_Vehicle)
        {
            float  fuelLeft;
            float  CargoVolume;
            bool   dangerousMaterials;
            float  wheelsCurrentAirPressure;
            string wheelMaker;

            fuelLeft           = enterEnergyLeft(i_IsElectric, i_Vehicle, k_TruckMaxFuel);
            dangerousMaterials = enterDangerousMaterialsInput();
            CargoVolume        = enterCargoVolume();
            getWheelInformation(out wheelMaker, out wheelsCurrentAirPressure, s_MyGarage.TruckMaxAirPressure);
            Truck newTruck = CreateVehicle.CreateTruck(i_TruckModel, i_LicencePlate, fuelLeft, dangerousMaterials, CargoVolume, wheelMaker, wheelsCurrentAirPressure, i_VehicleOwner);

            s_MyGarage.AddVehicleToGarage(newTruck);
        }
Example #5
0
        public void WithAPhoto_ThenInvokesVehicleRepositoryToUpdatePhotoInfo()
        {
            var vehicleForm = new VehicleFormModel {
                Name = "vehicle"
            };
            var photoStream = Mock.MockPhotoStream();

            var handler = new CreateVehicle(_vehicleRepo.Object, _photoRepo.Object);

            handler.Execute(UserId, vehicleForm, photoStream.Object);

            _vehicleRepo
            .Verify(r => r.Create(UserId, It.IsAny <Vehicle>()), Times.Once());

            _vehicleRepo
            .Verify(r => r.Update(It.IsAny <Vehicle>()), Times.Once());
        }
Example #6
0
        public async Task <IActionResult> CreateVehicle(CreateVehicle command)
        {
            try
            {
                _logger.LogInformation("Vehicle method fired on {date}", DateTime.Now);
                var result = await _mediator.Send(command);

                _logger.LogInformation("Vehicle method task finished on {date}", DateTime.Now);
                return(Ok(result));
            }
            catch (Exception e)
            {
                _logger.LogInformation("Vehicle method task finished on {date}", DateTime.Now);
                _logger.LogError($"Error in Vehicle method: {e.Message}");
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error in Vehicle method"));
            }
        }
        private async Task CreateVehicleWithImageAsync(string id)
        {
            var image  = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
            var stream = new MemoryStream();

            image.Save(stream, ImageFormat.Bmp);
            byte[] imageBytes    = stream.ToArray();
            var    model         = EntitiesFactory.NewModel().Save();
            var    createVehicle = new CreateVehicle
            {
                Id      = id ?? RandomId.NewId(),
                FuelId  = EFuel.Flex,
                ColorId = EColor.Black,
                Year    = 2010,
                ModelId = model.Id
            };

            createVehicle.ImageBase64 = Convert.ToBase64String(imageBytes);
            await MutationsHandler.Handle(createVehicle);
        }
        public void Test_Factory1()
        {
            CreateVehicle redCarFactory   = () => new Car(Color.Red);
            CreateVehicle blueMotoFactory = () => new Moto(Color.Blue);

            IList <IVehicle> redCars = Create5(redCarFactory);

            Assert.Equal(5, redCars.Count);
            Assert.Equal("Car Red", redCars[0].ToString());
            Assert.Equal("Car Red", redCars[1].ToString());
            Assert.Equal("Car Red", redCars[2].ToString());
            Assert.Equal("Car Red", redCars[3].ToString());
            Assert.Equal("Car Red", redCars[4].ToString());

            IList <IVehicle> blueMotos = Create5(blueMotoFactory);

            Assert.Equal(5, blueMotos.Count);
            Assert.Equal("Moto Blue", blueMotos[0].ToString());
            Assert.Equal("Moto Blue", blueMotos[1].ToString());
            Assert.Equal("Moto Blue", blueMotos[2].ToString());
            Assert.Equal("Moto Blue", blueMotos[3].ToString());
            Assert.Equal("Moto Blue", blueMotos[4].ToString());
        }
Example #9
0
 public async Task <ActionResult <MutationResult> > CreateAsync([FromBody] CreateVehicle mutation)
 {
     return(GetResult(await _mutationsHanlder.Handle(mutation)));
 }
 /// <summary>
 /// Method to run private method CreateVehicle
 /// </summary>
 public void StartGenerateVehicle()
 {
     CreateVehicle.Start();
 }
 /// <summary>
 /// Constructor for this class
 /// </summary>
 public VehicleQueue()
 {
     InitializeComponent();
     CreateVehicle.Start();
 }
Example #12
0
 public PostVehiclesController(CreateVehicle createVehicle)
 {
     this.createVehicle = createVehicle;
 }
 public static IList <IVehicle> Create5(CreateVehicle createVehicle)
 {
     return(Enumerable.Range(0, 5).Select(i => createVehicle()).ToList());
 }
Example #14
0
        private void addNewVehicleToGarage()
        {
            string licensePlate   = m_UserInputs.getLicensePlate();
            float  maxAirPressure = 0;
            float  maxBatteryTime = 0;

            FuelVehicle.eFuelType fuelType;
            Vehicle.eTireAmount   tireAmount;

            if (m_Garage.m_AllVehiclesInTheGarage.ContainsKey(licensePlate))
            {
                m_Garage.changeVehicleStatus(licensePlate, Client.eVehicleStatus.Repairing);
                m_UserInputs.vehicleAlreadyInGarageMessage();
            }
            else
            {
                string vehicleModel             = m_UserInputs.getValidString("Please enter vehicle model name:");
                string ownerName                = m_UserInputs.getValidString("Please enter Owner Name");
                string ownerPhone               = m_UserInputs.getOwnerPhone();
                float  percentOfRemainingEnergy = 0;
                Client newClient                = null;

                CreateVehicle.eVehicleType vehicleType = (CreateVehicle.eVehicleType)m_UserInputs.getVehicleType();

                string      tiresManufacturer = m_UserInputs.getValidString("Please enter the tires manufacturer:");
                float       currentTireAirPressure;
                List <Tire> listOfTires;
                Vehicle     vehicleForProperty;

                if (vehicleType == CreateVehicle.eVehicleType.ElectricCar || vehicleType == CreateVehicle.eVehicleType.FuelCar)
                {
                    maxAirPressure         = (float)Tire.eMaxAirPressure.Car;
                    currentTireAirPressure = m_UserInputs.getTiresPressure(maxAirPressure);
                    tireAmount             = Vehicle.eTireAmount.Car;
                    listOfTires            = CreateVehicle.createListOfTires(tireAmount, tiresManufacturer, currentTireAirPressure, maxAirPressure);
                    Car.eColor         carColor      = m_UserInputs.getCarColor();
                    Car.eNumberOfDoors numberOfDoors = m_UserInputs.getNumberOfDoors();
                    Car car = CreateVehicle.createCar(carColor, numberOfDoors);

                    if (vehicleType == CreateVehicle.eVehicleType.ElectricCar)
                    {
                        float remainingBatteryTime = m_UserInputs.getRemainingBatteryTime(ElectricCar.k_MaxBatteryTime);
                        percentOfRemainingEnergy = Vehicle.getPercentOfEnergy(remainingBatteryTime, ElectricCar.k_MaxBatteryTime);
                        ElectricCar electricCar = CreateVehicle.createElectricCar(car, remainingBatteryTime, maxBatteryTime, vehicleModel, licensePlate, percentOfRemainingEnergy, listOfTires);
                        newClient = CreateVehicle.createClient(ownerName, ownerPhone, Client.eVehicleStatus.Repairing, electricCar);
                    }
                    else
                    {
                        fuelType = FuelVehicle.eFuelType.Octan98;
                        float currentAmountOfFuel = m_UserInputs.getCurrentAmountOfFuel(FuelCar.k_MaxAmountOfFuel);
                        percentOfRemainingEnergy = Vehicle.getPercentOfEnergy(currentAmountOfFuel, FuelCar.k_MaxAmountOfFuel);
                        FuelCar fuelCar = CreateVehicle.createFuelCar(car, fuelType, currentAmountOfFuel, vehicleModel, licensePlate, percentOfRemainingEnergy, listOfTires);
                        newClient = CreateVehicle.createClient(ownerName, ownerPhone, Client.eVehicleStatus.Repairing, fuelCar);
                    }

                    vehicleForProperty = newClient.m_Vehicle;
                    Car.setProperties(vehicleForProperty, carColor, numberOfDoors);
                }
                else if (vehicleType == CreateVehicle.eVehicleType.ElectricMotorcycle || vehicleType == CreateVehicle.eVehicleType.FuelMotorcycle)
                {
                    maxAirPressure         = (float)Tire.eMaxAirPressure.Motorcycle;
                    currentTireAirPressure = m_UserInputs.getTiresPressure(maxAirPressure);
                    tireAmount             = Vehicle.eTireAmount.Motorcycle;
                    listOfTires            = CreateVehicle.createListOfTires(tireAmount, tiresManufacturer, currentTireAirPressure, maxAirPressure);
                    Motorcycle.eTypeOfLicense typeOfLicense = m_UserInputs.getTypeOfLicense();
                    int        engineCapacity = m_UserInputs.getValidInt("Please enter engine capacity:", 0, int.MaxValue);
                    Motorcycle motorCycle     = CreateVehicle.createMotorcycle(typeOfLicense, engineCapacity);

                    if (vehicleType == CreateVehicle.eVehicleType.ElectricMotorcycle)
                    {
                        float remainingBatteryTime = m_UserInputs.getRemainingBatteryTime(ElectricMotorcycle.k_MaxBatteryTime);
                        percentOfRemainingEnergy = Vehicle.getPercentOfEnergy(remainingBatteryTime, ElectricMotorcycle.k_MaxBatteryTime);
                        ElectricMotorcycle electricMotorcycle = CreateVehicle.createElectricMotorcycle(motorCycle, remainingBatteryTime, vehicleModel, licensePlate, percentOfRemainingEnergy, listOfTires);
                        newClient = CreateVehicle.createClient(ownerName, ownerPhone, Client.eVehicleStatus.Repairing, electricMotorcycle);
                    }
                    else
                    {
                        fuelType = FuelVehicle.eFuelType.Octan95;
                        float currentAmountOfFuel = m_UserInputs.getCurrentAmountOfFuel(FuelMotorcycle.k_MaxAmountOfFuel);
                        percentOfRemainingEnergy = Vehicle.getPercentOfEnergy(currentAmountOfFuel, FuelMotorcycle.k_MaxAmountOfFuel);
                        FuelMotorcycle fuelMotorcycle = CreateVehicle.createFuelMotorcycle(motorCycle, fuelType, currentAmountOfFuel, vehicleModel, licensePlate, percentOfRemainingEnergy, listOfTires);
                        newClient = CreateVehicle.createClient(ownerName, ownerPhone, Client.eVehicleStatus.Repairing, fuelMotorcycle);
                    }

                    vehicleForProperty = newClient.m_Vehicle;
                    Motorcycle.setProperties(vehicleForProperty, typeOfLicense, engineCapacity);
                }
                else if (vehicleType == CreateVehicle.eVehicleType.Truck)
                {
                    maxAirPressure         = (float)Tire.eMaxAirPressure.Truck;
                    currentTireAirPressure = m_UserInputs.getTiresPressure(maxAirPressure);
                    tireAmount             = Vehicle.eTireAmount.Truck;
                    listOfTires            = CreateVehicle.createListOfTires(tireAmount, tiresManufacturer, currentTireAirPressure, maxAirPressure);
                    fuelType = FuelVehicle.eFuelType.Soler;
                    bool  carrierDangerousMaterials = m_UserInputs.getIfCarrierDangerousMaterials();
                    float maximumCarryingWeight     = m_UserInputs.getValidFloat("Please enter maximum carry weight:", 0, int.MaxValue);
                    Truck truck = CreateVehicle.createTruck(carrierDangerousMaterials, maximumCarryingWeight);
                    float currentAmountOfFuel = m_UserInputs.getCurrentAmountOfFuel(FuelTruck.k_MaxAmountOfFuel);
                    percentOfRemainingEnergy = Vehicle.getPercentOfEnergy(currentAmountOfFuel, FuelTruck.k_MaxAmountOfFuel);
                    FuelTruck fuelTruck = CreateVehicle.createFuelTruck(truck, fuelType, currentAmountOfFuel, vehicleModel, licensePlate, percentOfRemainingEnergy, listOfTires);
                    newClient          = CreateVehicle.createClient(ownerName, ownerPhone, Client.eVehicleStatus.Repairing, fuelTruck);
                    vehicleForProperty = newClient.m_Vehicle;
                    Truck.setProperties(vehicleForProperty, carrierDangerousMaterials, maximumCarryingWeight);
                }

                m_Garage.addVehicle(newClient);
                m_UserInputs.suceededToAddMessage();
            }

            System.Console.ReadLine();
        }