Ejemplo n.º 1
0
        private static void InitializeCars()
        {
            BMW1 = new Car(new HybridEngine(), "BMW", "Model1", "Driver1"); BMW1.Engine.Fill(FuelType.Electricity);BMW1.VehicleStarted += OnVehicleStarted; BMW1.VehicleStopped += OnVehicleStopped;
            BMW2 = new Car(new ElectricEngine(), "BMW", "Model2", "Driver2"); BMW2.Engine.Fill(FuelType.Electricity); BMW2.VehicleStarted += OnVehicleStarted; BMW2.VehicleStopped += OnVehicleStopped;

            Audi1 = new Car(new ElectricEngine(), "Audi", "Model3", "Driver3"); Audi1.Engine.Fill(FuelType.Electricity); Audi1.VehicleStarted += OnVehicleStarted; Audi1.VehicleStopped += OnVehicleStopped;
            Audi2 = new Car(new ElectricEngine(), "Audi", "Model4", "Driver4"); Audi2.Engine.Fill(FuelType.Electricity); Audi2.VehicleStarted += OnVehicleStarted; Audi2.VehicleStopped += OnVehicleStopped;

            Mercedes = new Car(new PetrolEngine(), "Mercedes", "Model5", "Driver5"); Mercedes.Engine.Fill(FuelType.Petrol); Mercedes.VehicleStarted += OnVehicleStarted; Mercedes.VehicleStopped += OnVehicleStopped;
            Volvo = new Car(new PetrolEngine(), "Volvo", "Model6", "Driver6"); Volvo.Engine.Fill(FuelType.Petrol); Volvo.VehicleStarted += OnVehicleStarted; Volvo.VehicleStopped += OnVehicleStopped;
            Peugot = new Car(new PetrolEngine(), "Peugot", "Model7", "Driver7"); Peugot.Engine.Fill(FuelType.Petrol); Peugot.VehicleStarted += OnVehicleStarted; Peugot.VehicleStopped += OnVehicleStopped;
        }
Ejemplo n.º 2
0
 public void TestCarStart()
 {
     IVehicle raceCar = new Car(new PetrolEngine(), "Mercedes", "McLaren", "Mika Hakkinen");
     bool isFired = false;
     VehicleStartedEventArgs args = null;
     raceCar.VehicleStarted += delegate (object o, VehicleStartedEventArgs e) { isFired = true;args = e;  };
     Assert.IsFalse(isFired);
     raceCar.Start(0);
     Assert.IsFalse(isFired);
     raceCar.Engine.Fill(FuelType.Petrol);
     raceCar.Start(0);
     Assert.IsTrue(isFired);
     Assert.IsTrue(args.CarMake == "Mercedes");
     Assert.IsTrue(args.CarModel == "McLaren");
     Assert.IsTrue(args.DriverName == "Mika Hakkinen");
 }
Ejemplo n.º 3
0
 public void TestCarStop()
 {
     IVehicle raceCar = new Car(new PetrolEngine(), "Mercedes", "McLaren", "Mika Hakkinen");
     bool isFired = false;
     VehicleStoppedEventArgs args = null;
     raceCar.VehicleStopped += delegate (object o, VehicleStoppedEventArgs e) { isFired = true; args = e; };
     Assert.IsFalse(isFired);
     raceCar.Stop(1000);
     Assert.IsFalse(isFired);
     raceCar.Engine.Fill(FuelType.Petrol);
     raceCar.Start(0);
     Thread.Sleep(20000);
     raceCar.Stop(1000);
     Assert.IsTrue(isFired);
     Assert.IsTrue(Math.Round(args.AverageSpeed) == 50);
     Assert.IsTrue(args.CarMake == "Mercedes");
     Assert.IsTrue(args.CarModel == "McLaren");
 }