public void Adapter_TestAdapter_True() { var factory = new CarFactory(); target.AddProvider(new CarAdapter(factory.CreateInstance(CarType.Electric))); target.AddProvider(new CarAdapter(factory.CreateInstance(CarType.Diesel))); target.SendMeasurements(); Assert.True(true); }
public void CollectionTest_CollectionItems_True() { var collection = new CarCollection(); var factory = new CarFactory(); collection.AddItem(factory.CreateInstance(CarType.Smart)); collection.AddItem(factory.CreateInstance(CarType.Smart)); collection.AddItem(factory.CreateInstance(CarType.Diesel)); collection.AddItem(factory.CreateInstance(CarType.Electric)); collection.AddItem(factory.CreateInstance(CarType.Smart)); foreach (ICar sensor in collection) { sensor.Run(); } }
public void SensorFactory_CreatedSensor_True() { ICollection <ICar> cars = new List <ICar> { _factory.CreateInstance(CarType.Electric), _factory.CreateInstance(CarType.Diesel), _factory.CreateInstance(CarType.Electric) }; foreach (var car in cars) { car.Run(); } Assert.AreEqual(typeof(ElectricCar), cars.ElementAt(0).GetType()); }
public IHyperion CreateInstance(List <IHyperion> hyperions) { IHyperion productInstance = null; switch (hyperions.GetType().Name) { case "Sedan": productInstance = CarFactory <IHyperion, Sedan> .CreateInstance(); break; case "Coupe": productInstance = CarFactory <IHyperion, Coupe> .CreateInstance(); break; case "Sport": productInstance = CarFactory <IHyperion, Sport> .CreateInstance(); break; } return(productInstance); }
static void CreateHyperionCars() { var carRequirements = new CarProductRequirements(); var hyperions = new List <IHyperion> { new Sedan(), new Coupe(), new Sport() }; foreach (var hyperion in hyperions) { switch (hyperion.GetType().Name) { case "Sedan": var sedanCarCreator = new CarFactory <IHyperionCreator, SedanCreator>(); var sedanSpecifications = carRequirements.CreateProductSpecs(hyperion.GetType().Name, 4, 2); var counter = 0; foreach (var productSpec in sedanSpecifications) { counter++; var finishProduct = sedanCarCreator.CreateInstance().HyperionModelCreator(productSpec); ShowProduct(finishProduct, counter); System.Console.WriteLine(sedanCarCreator.StartEngine("Welcome to Hyperion")); System.Console.WriteLine("------------------------------------"); System.Console.WriteLine(Environment.NewLine); } break; case "Coupe": var coupCarCreator = new CarFactory <IHyperionCreator, CoupeCreator>(); var soupeSpecifications = carRequirements.CreateProductSpecs(hyperion.GetType().Name, 2, 2); counter = 0; foreach (var productSpec in soupeSpecifications) { counter++; var finishProduct = coupCarCreator.CreateInstance().HyperionModelCreator(productSpec); ShowProduct(finishProduct, counter); System.Console.WriteLine(coupCarCreator.StartEngine("Welcome to Hyperion")); System.Console.WriteLine("------------------------------------"); System.Console.WriteLine(Environment.NewLine); } break; case "Sport": var sportCarCreator = new CarFactory <IHyperionCreator, SportCreator>(); var sportCarSpecifications = carRequirements.CreateProductSpecs(hyperion.GetType().Name, 20, 2, 3); var counter1 = 0; foreach (var productSpec in sportCarSpecifications) { counter1++; var finishProduct = sportCarCreator.CreateInstance().HyperionModelCreator(productSpec); ShowProduct(finishProduct, counter1); System.Console.WriteLine(sportCarCreator.StartEngine("Sport Mode Engaged")); System.Console.WriteLine("------------------------------------"); System.Console.WriteLine(Environment.NewLine); } break; } } }