public void ShouldCreatePaginationSet_SortBy_Reverse() { // Arrange var queryable = CarFactory.GenerateCarsList("BMW", "X", 3) .Union(CarFactory.GenerateCarsList("Audi", "A", 3)) .Union(CarFactory.GenerateCarsList("Mercedes", "G", 3)) .AsQueryable(); var pagingInfo = new PagingInfo { CurrentPage = 1, ItemsPerPage = 5, SortBy = "Model", Reverse = true }; // Act var paginationSet = pagingInfo.CreatePaginationSet <Car, CarDto>(queryable, CarFactory.MapCarsToCarDtos); // Assert paginationSet.Should().NotBeNull(); paginationSet.Items.Should().HaveCount(5); paginationSet.Items.ElementAt(0).ToString().Should().Be("BMW X 2, Year 2019"); paginationSet.Items.ElementAt(1).ToString().Should().Be("BMW X 1, Year 2019"); paginationSet.Items.ElementAt(2).ToString().Should().Be("BMW X 0, Year 2019"); paginationSet.Items.ElementAt(3).ToString().Should().Be("Mercedes G 2, Year 2019"); paginationSet.Items.ElementAt(4).ToString().Should().Be("Mercedes G 1, Year 2019"); paginationSet.CurrentPage.Should().Be(1); paginationSet.TotalPages.Should().Be(2); paginationSet.TotalCount.Should().Be(9); paginationSet.TotalCountUnfiltered.Should().Be(9); }
public ActionResult Details(int id) { var factory = new CarFactory(); Car found = factory.Cars.Where(p => p.Car_ID == id).FirstOrDefault(); return(View(found)); }
public void ShouldCreatePaginationSet_WithFilter_WithNumberRanges() { // Arrange var queryable = CarFactory.GenerateCarsList("BMW", "X", null, 2000, 3) .Union(CarFactory.GenerateCarsList("BMW", "X", 5000m, 2005, 3)) .Union(CarFactory.GenerateCarsList("BMW", "X", 10000m, 2010, 3)) .Union(CarFactory.GenerateCarsList("BMW", "X", 15000m, 2015, 3)) .AsQueryable(); var pagingInfo = new PagingInfo { Filter = new Dictionary <string, object> { { "Name", "bmw" }, { "model", "x" }, { "Price", ">=5000" }, { "year", "<2010" } } }; // Act var paginationSet = pagingInfo.CreatePaginationSet <Car, CarDto>(queryable, CarFactory.MapCarsToCarDtos); // Assert paginationSet.Should().NotBeNull(); paginationSet.Items.Should().HaveCount(3); paginationSet.Items.ElementAt(0).ToString().Should().Be("BMW X 0, Year 2005"); paginationSet.Items.ElementAt(1).ToString().Should().Be("BMW X 1, Year 2005"); paginationSet.Items.ElementAt(2).ToString().Should().Be("BMW X 2, Year 2005"); paginationSet.CurrentPage.Should().Be(1); paginationSet.TotalPages.Should().Be(1); paginationSet.TotalCount.Should().Be(3); paginationSet.TotalCountUnfiltered.Should().Be(12); }
public ActionResult DeleteSpecials(Specials sp) { var repo = CarFactory.Create(); repo.DeleteSpecial(sp.SpecialId); return(RedirectToAction("Specials")); }
public void BuildTestContext(CarFactory cf) { AbstractCar c1 = cf.CreateCar(); AbstractCar c2 = cf.CreateCar(); AbstractCar c3 = cf.CreateCar(); AbstractCar c4 = cf.CreateCar(); }
public CarService(CarFactory carFactory, ICarRentalUnitOfWork unitOfWork, CarMapper carMapper) { _carMapper = carMapper; _unitOfWork = unitOfWork; _carFactory = carFactory; }
static void Main(string[] args) { // Instantiate a CarFactory var carFactory = new CarFactory(); // From the car factory, we can ask it to create new Cars. // We give a Type of car that we want and it will return us that car var corsa = carFactory.Create(Model.CORSA, Color.BLACK); var astra = carFactory.Create(Model.ASTRA, Color.GREY); for (int i = 0; i < 5; i++) // accelerate astra 5 times { Console.WriteLine($"{astra.GetBrand()} {astra.GetModel()}: {astra.Accelerate()}"); } Console.WriteLine(); for (int i = 0; i < 3; i++) // accelerate corsa 3 times { Console.WriteLine($"{corsa.GetBrand()} {corsa.GetModel()}: {corsa.Accelerate()}"); } Console.WriteLine(); Console.WriteLine($"{corsa.GetBrand()} {corsa.GetModel()}: {corsa.Break()}"); // corsa used breaks 1 time Console.WriteLine(); Console.WriteLine($"{corsa.GetBrand()} {corsa.GetModel()} is going at {corsa.GetCurrentSpeed()}"); Console.WriteLine($"{astra.GetBrand()} {astra.GetModel()} is going at {astra.GetCurrentSpeed()}"); }
private void btnSave_Click(object sender, RoutedEventArgs e) { ForceValidation(); if (Validation.GetHasError(txtRegNo) || Validation.GetHasError(txtColor) || Validation.GetHasError(txtCompany) || Validation.GetHasError(txtModel)) { MessageBox.Show("Error Some Data is Missing", "ERROR"); return; } Car_Table obj = new Car_Table(); obj.CA_RegNo = txtRegNo.Text.Trim(); obj.CA_Color = txtColor.Text.Trim(); obj.CA_Company = txtCompany.Text.Trim(); obj.CA_Model = int.Parse(txtModel.Text); obj.CA_Status = true; CarFactory CFobj = new CarFactory(); if (CFobj.insert(obj)) { MessageBox.Show("Car is Added Successfully", "Data Saved"); } else { MessageBox.Show("Data Is not Added", "Error"); } txtRegNo.Text = " "; }
public void CreateInstanceTest() { var vehicle1 = new CarFactory(); var vehicle2 = new MotorbikeFactory(); var vehicle3 = new BikeFactory(); vehicle1.Should().BeOfType <CarFactory>(); vehicle2.Should().BeOfType <MotorbikeFactory>(); vehicle3.Should().BeOfType <BikeFactory>(); var car = vehicle1.Factory(); car.Name.Should().Be("Car"); car.Wheels.Should().Be(4); car.HasEngine.Should().BeTrue(); var motorBike = vehicle2.Factory(); motorBike.Name.Should().Be("Motorbike"); motorBike.Wheels.Should().Be(2); motorBike.HasEngine.Should().BeTrue(); var bike = vehicle3.Factory(); bike.Name.Should().Be("Bike"); bike.Wheels.Should().Be(2); bike.HasEngine.Should().BeFalse(); }
private void AddVehicles() { for (int i = 1; i <= 3; i++) { string[] vehicleArgs = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); Vehicle vehicle = null; if (i == 1) { vehicle = CarFactory.CreateCar(vehicleArgs); } else if (i == 2) { vehicle = TruckFactory.CreateTruck(vehicleArgs); } else { vehicle = BusFactory.CreateBus(vehicleArgs); } vehicles.Add(vehicle); } }
/* * Implementation details: * - Start with interface * - Add "functionality" using virtual properties in the abstract class * * - Downside of Abstract Factory pattern: * - If new functionality is needed (e.g. Trailer Hitch parts), then that * functionality must be added using the same (pardon the pun) pattern * e.g. Add the interface, then add the abstract class, then add the * functionality where necessary by modifying the appropriate factory * method. */ static void Main() { WhatToMake WHAT_VEHICLE_TO_MAKE = WhatToMake.Car; AbstractVehicleFactory vFactory; switch (WHAT_VEHICLE_TO_MAKE) { case WhatToMake.Car: { vFactory = new CarFactory(); break; } case WhatToMake.Van: { vFactory = new VanFactory(); break; } default: { throw new Exception("Unhandled vehicle type selected!"); } } IBody vBody = vFactory?.CreateBody(); IChassis vChassis = vFactory?.CreateChassis(); IGlassware vGlassware = vFactory?.CreateGlassware(); WriteLine(vBody.BodyParts); WriteLine(vChassis.ChassisParts); WriteLine(vGlassware.GlasswareParts); ReadKey(); }
private static void FactoryPatternCar() { CarFactory carFactory = new CarFactory(); var car = carFactory.GetCar(Patterns.Creational.FactoryMethod.Brand.Honda).GetCar(); Console.WriteLine(car.ToString()); }
public void ICar GetRedCar() { var result = CarFactory.Create("Tesla"); result.Color = Color.Red; return(result); }
public CarCatalog(CarFactory carFactory, EngineFactory engineFactory, TireFactory tireFactory) { this.cars = new List <Car>(); this.carFactory = carFactory; this.engineFactory = engineFactory; this.tireFactory = tireFactory; }
static void Main(string[] args) { Console.WriteLine("ENTER TO CONTINUE TO NEXT PATTERN..\n1 = Factory Method\n2 = Singleton"); List <Car> cars = new List <Car>(); CarFactory factory = new CarFactory(); cars.Add(factory.GetCar(CarType.Compact, "Peugotje", "Peugot")); cars.Add(factory.GetCar(CarType.Motorcycle, "Hondatje", "Honda")); cars.Add(factory.GetCar(CarType.Sports, "Lambotje", "Lambo")); foreach (Car c in cars) { Console.WriteLine(c); Console.WriteLine(c.Sound() + "\n"); } Console.ReadLine(); GameApplication appl = GameApplication.GetInstance(); appl.Name = "Pakimon Go"; Console.WriteLine(appl); //Using the default constructor doesn't work for the GameApplication class! Neither does inheriting from this class work. Console.ReadLine(); AppleFactory appleFactory = new AppleFactory(); Console.WriteLine(appleFactory.GetFood()); BananaFactory bananaFactory = new BananaFactory(); Console.WriteLine(bananaFactory.GetFood()); Console.ReadLine(); }
public Client() { var whatToMake = "car"; AbstractVehicleFactory factory = null; if (whatToMake.Equals("car")) { factory = new CarFactory(); } if (whatToMake.Equals("van")) { factory = new VanFactory(); } if (factory == null) { return; } var vehicleBody = factory.CreateBody(); var vehicleChassis = factory.CreateChassis(); var vehicleGlassware = factory.CreateGlassware(); Console.WriteLine(vehicleBody.BodyParts); Console.WriteLine(vehicleChassis.ChassisParts); Console.WriteLine(vehicleGlassware.GlasswareParts); }
public void Register(int id, string type, string brand, string model, int yearOfProduction, int horsepower, int acceleration, int suspension, int durability) { var car = CarFactory.MakeCar(id, type, brand, model, yearOfProduction, horsepower, acceleration, suspension, durability); cars.Add(id, car); }
//Deprecated (originally used for testing - would still work with a revision) public void SpawnCars(int howmany) { if (vehicles == null) { vehicles = new List <Car>(); } //map.roads.Count int toSpawn = howmany; int spawned = 0; float prob = 0.02f; for (int i = 0; spawned < toSpawn; i++) { if (AllParkingOccupied()) { return; } foreach (ParkingSpace parking in parkingSpots) { if (UnityEngine.Random.Range(0f, 1f) < prob && !parking.occupied) { Car c = CarFactory.CreateCar(parking.road); vehicles.Add(c); spawned++; } } } }
// GET: Cars public ActionResult CarsList() { var factory = new CarFactory(); var viewModel = new CarsListViewModel(factory.Cars); return(View(viewModel)); }
public static void Main(string[] args) { var joesEngineFactory = new EngineFactory(); var v4 = joesEngineFactory.Create(4); var car1 = new Car { Engine = v4 }; var car2 = new Car { Engine = v4 }; System.Console.WriteLine(car1.Engine.IsBroken); car2.Engine.IsBroken = true; System.Console.WriteLine(car1.Engine.IsBroken); var natesCarFactory = new CarFactory() { EngineFactory = joesEngineFactory }; var mustang = natesCarFactory.CreateNewMustang(); }
public static void Used() { var factory = new CarFactory(); var xiaoke = factory.ProduceCar <XiaoKeCar>(new XiaoKeCarConfig()); var jeep = factory.ProduceCar <JeepCar>(new JeepConfig()); var haval = factory.ProduceCar <HavalCar>(new HavalCarConfig()); }
static void Main() { // Econical car, blue VehicleFactory vCarFactory = new CarFactory(); IVehicle vCar = vCarFactory.Build (VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue); WriteLine(vCar); // White van VehicleFactory vVanFactory = new VanFactory(); IVehicle vVan = vVanFactory.Build (VehicleFactory.DrivingStyle.Powerful, VehicleColour.White); WriteLine(vVan); // Red Sports car using static factory IVehicle vSportsVehicle = VehicleFactory.Make ( VehicleFactory.BuildWhat.Car , VehicleFactory.DrivingStyle.Powerful , VehicleColour.Red ); WriteLine(vSportsVehicle); ReadKey(); }
public static IVehicle GetStartedVehicle <TVehicle>() where TVehicle : class, IVehicle, new() { IVehicleFactory factory; switch (new TVehicle()) { case Car c: factory = new CarFactory(); break; case Truck t: factory = new TruckFactory(); break; default: throw new NotImplementedException(); } var result = factory.CreateVehicle(); result.Start(); //Return IVehicle and NOT TVehicle //TVehicle would be the concrete type, we want the abstract type (IVehicle). return(result); }
static void Main(string[] args) { ComputerFactory factory = null; if (args.Length > 0 && args[0] == "BrandX") { factory = new BrandXFactory(); } else { factory = new ConcreteComputerFactory(); } new ComputerAssembler().AssembleComputer(factory); // Add in Product Factory var product = new Product(); Console.WriteLine("Enter a product name: "); product.Name = Console.ReadLine(); product.Description = "A New Product"; Console.WriteLine("Enter a price: "); product.Price = Convert.ToInt32(Console.ReadLine()); // With Bank using BestForMe PaymentProcessor payment = new PaymentProcessor(); payment.MakePayment(PaymentMethod.BEST_FOR_ME, product); // Try with PayPal has access to all the payment methods PaymentProcessor2 paypal = new PaymentProcessor2(); paypal.MakePayment(PaymentMethod.PAYPAL, product); // Added BillDesk Payment PaymentProcessor2 payment2 = new PaymentProcessor2(); payment2.MakePayment(PaymentMethod.BILL_DESK, product); Console.WriteLine(product.Name + ' ' + product.Price); Console.WriteLine("Now the Cars portion of the program."); Console.Read(); // Cars var fordFiestaFactory = new FordFiestaFactory(); var fordFiesta = fordFiestaFactory.CreateCar("Blue"); Console.WriteLine("Brand: {0} \nModel: {1} \nColor: {2}", fordFiesta.Make, fordFiesta.Model, fordFiesta.Color); Console.Read(); Console.WriteLine("\n"); ICarSupplier objCarSupplier = CarFactory.GetCarInstance(2); objCarSupplier.GetCarModel(); Console.WriteLine(" and color is " + objCarSupplier.CarColor); Console.Read(); Console.Read(); } //Main
public void TestMethod1() { var carFactory = new CarFactory(); var carsArray = new Cars(new ICar[] { carFactory.GetProduct("Audi"), carFactory.GetProduct("Mercedes"), carFactory.GetProduct("BMW"), carFactory.GetProduct("Audi"), }); int[] intArray ={ 1, 2, 3, 4, 5 }; /* Array myArray2 = Array.CreateInstance() IList list = myArray2;*/ List<string> list = new List<string>(5); LinkedList<int> acs = new LinkedList<int>(); // LinkedL // //This throws Exception // list.Add(5); foreach (ICar car in carsArray) { var value = car.Desc(); } }
public void ShouldThrowNotSupportedExceptionWhenTypeIsInvalid(string type) { var carFactory = new CarFactory(); Action getCar = () => carFactory.CreateCar(type); getCar.Should().ThrowExactly <NotSupportedException>(); }
public Driver CreateDriver(List <string> inputData) { //• RegisterDriver {type} {name} {hp} {fuelAmount} Ultrasoft {tyreHardness} {grip} string type, name; Car car; CarFactory carFactory = new CarFactory(); type = inputData[0]; name = inputData[1]; car = carFactory.GetCar(inputData.Skip(2).ToList()); switch (type) { case "AggressiveDriver": return(new AggressiveDriver(name, car)); case "EnduranceDriver": return(new EnduranceDriver(name, car)); default: throw new ArgumentException(Messages.missingDriverType); } }
public static void FactoryPatternDemo() { CarFactory carFactory = new CarFactory(); Car redBugatti = carFactory.GetCar("Bugatti", Color.RED); Car pinkPorche = carFactory.GetCar("Porche", Color.PINK); }
public void BDDScenario_1_1_TestCarCreation(string make, string model, string engine, int doors, int wheels, CarBodyType bodyType) { IVehicleFactory <Car, CreateCarCommand> factory = new CarFactory(); CreateCarCommand createCarCommand = new CreateCarCommand(make, model, engine, doors, wheels, bodyType); Car car = factory.Create(createCarCommand); Assert.NotNull(car); Assert.Equal(make, car.Make); Assert.Equal(model, car.Model); Assert.Equal(engine, car.Engine); Assert.Equal(doors, car.Doors); Assert.Equal(wheels, car.Wheels); Assert.Equal(bodyType, car.BodyType); }
public CarManager() { this.cars = new Dictionary <int, Car>(); this.races = new Dictionary <int, Race>(); this.garage = new Garage(); this.factory = new CarFactory(); }
public void RegisterDriver(List <string> commandArgs) { try { var driverType = commandArgs[0]; var driverName = commandArgs[1]; var hp = int.Parse(commandArgs[2]); var fuelAmount = double.Parse(commandArgs[3]); var tyreType = commandArgs[4]; var tyreHardness = double.Parse(commandArgs[5]); var grip = 0.0; Driver driver = null; Car car = null; Tyre tyre = null; if (tyreType == "Ultrasoft") { grip = double.Parse(commandArgs[6]); tyre = TyreFactory.CreateUltraSoft(tyreHardness, grip); } else if (tyreType == "Hard") { tyre = TyreFactory.CreateHard(tyreHardness); } car = CarFactory.CreateCar(hp, fuelAmount, tyre); driver = DriverFactory.CreateDriver(driverType, driverName, car); this.drivers.Add(driver); } catch { } }
public void CarFactoryTest() { CarFactory carFactory = new CarFactory(); ICar honda = carFactory.GetElement("Honda"); honda.Color = Color.Blue; ICar anotherHonda = carFactory.GetElement("Honda"); }
private static void Main(string[] args) { var cf = new CarFactory(); //工厂 Car c = cf.getCar("BMW"); if (c != null) { Console.WriteLine("您好,你的宝马我们已经帮您生产好了,请你有空前来提货并付款!"); } else { Console.WriteLine("不好意思,恕我无能为力!"); } Console.ReadLine(); }
public void CreateCarFactoryTest() { CarFactory carFactory = new CarFactory(); Assert.IsNotNull(carFactory); }
public static IVehicle Make(Category cat, DrivingStyle style, VehicleColour colour) { VehicleFactory factory; if (cat == Category.Car) { factory = new CarFactory(); } else { factory = new VanFactory(); } return factory.Build(style, colour); }
public static void Main() { // I want an economical car, coloured blue VehicleFactory carFactory = new CarFactory(); IVehicle car = carFactory.Build( VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue); Console.WriteLine(car); // I want a "white van" VehicleFactory vanFactory = new VanFactory(); IVehicle van = vanFactory.Build( VehicleFactory.DrivingStyle.Powerful, VehicleColour.White); Console.WriteLine(van); // use the static Make method to create a red sports car IVehicle sporty = VehicleFactory.Make( VehicleFactory.Category.Car, VehicleFactory.DrivingStyle.Powerful, VehicleColour.Red); Console.WriteLine(sporty); }
public static void Main() { // specify the platform here: "mac", "windows", "android" string whatToMake = "car"; // "van" AbstractVehicleFactory factory = null; // Create the correct 'factory'... if (whatToMake.Equals("car")) { factory = new CarFactory(); } else { factory = new VanFactory(); } // Create the vehicle's component parts ... // These will either be all car parts or all van parts // These can be widgets of different platforms - Mac, Windows, Android IBody vehicleBody = factory.CreateBody(); IChassis vehicleChassis = factory.CreateChassis(); IGlassware vehicleGlassware = factory.CreateGlassware(); // Show what we've created... Console.WriteLine(vehicleBody.BodyParts); Console.WriteLine(vehicleChassis.ChassisParts); Console.WriteLine(vehicleGlassware.GlasswareParts); vehicleBody.Draw(); }