示例#1
0
        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()}");
        }
        public void IsTypeFiat()
        {
            //Act
            var result = carFactory.Create(true);

            //Assert
            var fiat = Assert.IsType <Fiat>(result);

            Assert.Equal(fiat.GetName(), "Fiat");
        }
        public ActionResult DeleteSpecials(Specials sp)
        {
            var repo = CarFactory.Create();

            repo.DeleteSpecial(sp.SpecialId);
            return(RedirectToAction("Specials"));
        }
        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);
        }
示例#5
0
    public void ICar GetRedCar()
    {
        var result = CarFactory.Create("Tesla");

        result.Color = Color.Red;
        return(result);
    }
示例#6
0
        public void Add(string[] carArgs)
        {
            string model = carArgs[0];

            int engineSpeed = int.Parse(carArgs[1]);
            int enginePower = int.Parse(carArgs[2]);

            Engine engine = engineFactory.Create(engineSpeed, enginePower);

            int    cargoWeight = int.Parse(carArgs[3]);
            string cargoType   = carArgs[4];

            Cargo cargo = new Cargo(cargoWeight, cargoType);

            Tire[] tires = new Tire[4];

            int tireIndex = 5;

            for (int t = 0; t < tires.Length; t++)
            {
                double tirePressure = double.Parse(carArgs[tireIndex]);
                tireIndex++;
                int tireAge = int.Parse(carArgs[tireIndex]);
                tireIndex++;

                Tire tire = tireFactory.Create(tirePressure, tireIndex);

                tires[t] = tire;
            }

            Car car = carFactory.Create(model, engine, cargo, tires);

            cars.Add(car);
        }
        public ActionResult Modells()
        {
            var model = new ModelViewModel();

            model.Models = ctxs.GetAllModel();
            model.SetMakeItems(CarFactory.Create().GetAllMakes());
            return(View(model));
        }
        public ActionResult Details(int id)
        {
            Vehicle vehicle = new Vehicle();
            var     repo    = CarFactory.Create();

            vehicle = repo.GetVehicleById(id);
            return(View(vehicle));
        }
示例#9
0
    public void Register(int id, string type, string brand, string model, int yearOfProduction, int horsepower,
                         int acceleration, int suspension, int durability)
    {
        var car = CarFactory.Create(type, brand, model, yearOfProduction, horsepower, acceleration, suspension,
                                    durability);

        cars[id] = car;
    }
        public ActionResult DeleteSpecial(int id)
        {
            var model = CarFactory.Create();

            model.GetSpecialById(id);

            return(View(model));
        }
示例#11
0
    public void RegisterDriver(List <string> commandArgs)
    {
        var tyreFactory = new TyreFactory();
        var tyre        = tyreFactory.Create(commandArgs.Skip(4).ToArray());

        var carFactory = new CarFactory();
        var car        = carFactory.Create(commandArgs.Skip(2).Take(2).ToArray(), tyre);

        this.validDrivers.Add(new DriverFactory().Create(commandArgs.Take(2).ToArray(), car));
    }
示例#12
0
        //首先有一个抽象的工厂,然后具体的工厂继承抽象工厂,实现
        //每一个工厂只用来生产一种产物
        //虽然上层还是new了对象 但是屏蔽了底层的业务类
        public static void Show()
        {
            IFactory human = new HumanFactory();

            human.Create();

            IFactory car = new CarFactory();

            car.Create();
        }
示例#13
0
        public void Should_be_able_to_create_type_with_factory_method()
        {
            var container = new Container();

            container.Register <Wheels>();
            var car = container.New(
                Made.Of(() => CarFactory.Create(Arg.Of <Wheels>())));

            Assert.That(car.Wheels, Is.Not.Null);
            Assert.That(container.IsRegistered <Car>(), Is.False);
        }
示例#14
0
 public void RegisterDriver(List <string> commandArgs)
 {
     try
     {
         Tyre   tyre   = TyreFactory.Create(commandArgs);
         Car    car    = CarFactory.Create(commandArgs, tyre);
         Driver driver = DriverFactory.Create(commandArgs, car);
         string name   = commandArgs[1];
         racingDrivers.Add(driver);
     }
     catch (ArgumentException)
     { }
 }
        public ActionResult AddVehicle()
        {
            var model = new AddVehicleViewModel();

            model.SetMakeItems(CarFactory.Create().GetAllMakes());
            model.SetModelItems(CarFactory.Create().GetAllModel());
            model.SetBodyStyleItems();
            model.SetTypeItems();
            model.SetTransmissionItems();
            model.SetColorItems();
            model.SetInteriorItems();
            return(View(model));
        }
示例#16
0
        public void Caching_Query_Should_Respect_Provided_Predicate()
        {
            var collection      = CarFactory.Create();
            var storage         = new Cactus.Blade.Caching.Caching();
            var key             = Guid.NewGuid().ToString();
            var expected_brand  = "BMW";
            var expected_amount = collection.Count(c => c.Brand == expected_brand);

            storage.Store(key, collection);

            var target = storage.Query <Car>(key, c => c.Brand == expected_brand);

            target.Should().NotBeNull();
            target.Count().Should().Be(expected_amount);
            target.All(c => c.Brand == expected_brand);
        }
示例#17
0
        public void LocalStorage_Query_Should_Cast_Response_To_Collection()
        {
            // arrange - persist a collection to storage
            var collection      = CarFactory.Create();
            var storage         = new LocalStorage();
            var key             = Guid.NewGuid().ToString();
            var expected_amount = collection.Count();

            storage.Store(key, collection);

            // act - fetch directly as a collection, passing along a where-clause
            var target = storage.Query <Car>(key);

            // assert
            target.Should().NotBeNull();
            target.Count().Should().Be(expected_amount);
        }
        [InlineData("Honda", "Civic", "4 cylinder Petrol Aspirated 1.8L", 5, 20)] //Twenty num of wheels is incorrect for a car
        public void BDDScenario_1_1_2_HondaCivicHavingInvalidNumOfWheelsShouldFail(string make,
                                                                                   string model,
                                                                                   string engine,
                                                                                   int doors,
                                                                                   int wheels)
        {
            IVehicleFactory <Car, CreateCarCommand> factory = new CarFactory();
            CreateCarCommand createCarCommand = new CreateCarCommand(make,
                                                                     model,
                                                                     engine,
                                                                     doors,
                                                                     wheels,
                                                                     CarBodyType.Hatchback);

            var exception = Assert.Throws <ArgumentOutOfRangeException>(() => factory.Create(createCarCommand));

            Assert.Equal(nameof(Car.Wheels).ToLowerInvariant(), exception.ParamName.ToLowerInvariant());
        }
        public MainWindow()
        {
            InitializeComponent();

            var carFactory = new CarFactory(WIDTH, HEIGHT);
            var cars       = carFactory.Create(5);

            var docFactory = new DocFactory(WIDTH, HEIGHT);
            var docs       = docFactory.Create(500);

            var calculator = new Calculator();
            var routes     = calculator.CalcRoutes(docs, cars);

            var imageFactory = new ImageFactory(WIDTH, HEIGHT);

            var mainWindowViewModel = new MainWindowViewModel(routes, imageFactory);

            this.DataContext = mainWindowViewModel;
        }
示例#20
0
        public void LocalStorage_Query_Should_Respect_Provided_Predicate()
        {
            // arrange - persist a collection to storage
            var collection      = CarFactory.Create();
            var storage         = new LocalStorage();
            var key             = Guid.NewGuid().ToString();
            var expected_brand  = "BMW";
            var expected_amount = collection.Count(c => c.Brand == expected_brand);

            storage.Store(key, collection);

            // act - fetch directly as a collection, passing along a where-clause
            var target = storage.Query <Car>(key, c => c.Brand == expected_brand);

            // assert
            target.Should().NotBeNull();
            target.Count().Should().Be(expected_amount);
            target.All(c => c.Brand == expected_brand);
        }
示例#21
0
        static void Main(string[] args)
        {
            var index   = Console.ReadLine();
            var mileage = Console.ReadLine();
            var idx     = ToInt(index);
            var car     = CarFactory.Create(idx, mileage);

            if (car == null)
            {
                Console.WriteLine("Car not found! You must use 0,1,2 to the first line!");
            }
            else
            {
                Console.WriteLine(car.ToString());
            }

            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Press Enter to Finish");
            Console.ReadLine();
        }
示例#22
0
        public void CreateCar(CarDTO carDTO)
        {
            var car = _unitOfWork.CarRepository.Find(c => c.RegistrationNumber == carDTO.RegistrationNumber)
                      .FirstOrDefault();

            if (car != null)
            {
                throw new Exception($"Car with {carDTO.RegistrationNumber} registration number already exists.");
            }
            var rentalArea = _unitOfWork.RentalAreaRepository.Find(r => r.Id == carDTO.RentalAreaId).FirstOrDefault();

            if (rentalArea == null)
            {
                throw new Exception($"There is no rental area with {carDTO.RentalAreaId} id.");
            }
            car = _carFactory.Create(carDTO.Id, carDTO.RegistrationNumber, carDTO.CurrentDistance, carDTO.TotalDistance,
                                     carDTO.CurrentLatitude, carDTO.CurrentLongitude, carDTO.PricePerMinute, carDTO.RentalAreaId);
            if (!rentalArea.IsInArea(car.CurrentPosition))
            {
                throw new Exception("Starting position of car cannot be outside of bonds!");
            }
            _unitOfWork.CarRepository.Insert(car);
            _unitOfWork.Commit();
        }
示例#23
0
        public void CreatePorsheTest()
        {
            var car = CarFactory.Create("Porsche");

            Assert.Equal("Porsche", car.Name);
        }
示例#24
0
        public void CreateTrabantTest()
        {
            var car = CarFactory.Create("Trabant");

            Assert.Equal("Trabant", car.Name);
        }
        public void Create_SetsMakeValueInCarObjectToValuePassedIn(string make)
        {
            var result = _subject.Create(make, "test model", 9.65);

            Assert.Equal(make, result.Make);
        }
示例#26
0
        public void CreateNullTest()
        {
            var car = CarFactory.Create("Lotus");

            Assert.Equal("NullCar", car.Name);
        }