Esempio n. 1
0
        public void Cannot_Save_Invalid_Changes()
        {
            // Организация - создание имитированного хранилища данных
            Mock <IBMWRepository> mock = new Mock <IBMWRepository>();

            // Организация - создание контроллера
            AdminBMWController controller = new AdminBMWController(mock.Object);

            // Организация - создание объекта Game
            BMW game = new BMW {
                Name = "Test"
            };

            // Организация - добавление ошибки в состояние модели
            controller.ModelState.AddModelError("error", "error");

            // Действие - попытка сохранения товара
            ActionResult result = controller.Edit(game);

            // Утверждение - проверка того, что обращение к хранилищу НЕ производится
            mock.Verify(m => m.SaveBMW(It.IsAny <BMW>()), Times.Never());

            // Утверждение - проверка типа результата метода
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Esempio n. 2
0
        public void Cannot_Edit_Nonexistent_Game()
        {
            // Организация - создание имитированного хранилища данных
            Mock <IBMWRepository> mock = new Mock <IBMWRepository>();

            mock.Setup(m => m.BMWs).Returns(new List <BMW>
            {
                new BMW {
                    Id = 1, Name = "Игра1"
                },
                new BMW {
                    Id = 2, Name = "Игра2"
                },
                new BMW {
                    Id = 3, Name = "Игра3"
                },
                new BMW {
                    Id = 4, Name = "Игра4"
                },
                new BMW {
                    Id = 5, Name = "Игра5"
                }
            });

            // Организация - создание контроллера
            AdminBMWController controller = new AdminBMWController(mock.Object);

            // Действие
            BMW result = controller.Edit(6).ViewData.Model as BMW;

            // Assert
        }
Esempio n. 3
0
        public IAuto CreateAutoMobile()
        {
            var bmw = new BMW();

            bmw.ModelName = "BMW x5";
            return(bmw);
        }
Esempio n. 4
0
        public IAuto CreateAutomobile()
        {
            var bmw = new BMW();

            bmw.SetName("BMW X5");
            return(bmw);
        }
Esempio n. 5
0
        ICar <Engine>[] ICarFactory.Create()
        {
            Audi audi = new Audi()
            {
                Abs           = "1",
                CruiseControl = "s",
                Esp           = "s",
                Speed         = 200,
                FuelTank      = new FT3()
            };
            BMW bmw = new BMW()
            {
                Abs           = "1",
                CruiseControl = "s",
                Esp           = "s",
                Speed         = 250,
                FuelTank      = new FT3()
            };

            ICar <Engine>[] cars = new ICar <Engine>[]
            {
                audi,
                bmw
            };
            return(cars);
        }
        public async Task <Vehicle> Build(CreateVehicleCommand command)
        {
            Vehicle vehicle;

            try
            {
                VehicleTypes type;
                VehicleBody  body;

                Enum.TryParse <VehicleTypes>(command.Vehicle, out type);
                body = await _bodyHandler.Build(command.Body);

                switch (type)
                {
                case VehicleTypes.BMW:
                    vehicle = new BMW(command.Id, body, command.Color);
                    break;

                case VehicleTypes.Ford:
                    vehicle = new Ford(command.Id, body, command.Color);
                    break;

                default:
                    vehicle = null;
                    break;
                }
            }
            catch (Exception exception)
            {
                return(null);
            }

            return(vehicle);
        }
 public void WriteCar(Car car)
 {
     if (!File.Exists(pathCars))
     {
         using (StreamWriter streamWriter = File.CreateText(pathCars))
         {
             streamWriter.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}", "ID", "Model", "Registration Plate", "No. Seats", "Color", "Ax", "Ay", "Bx", "By", "Parked on", "HDAC", "Double Bass", "Speakers", "Oxygen System", "Bullet Proof Glass", "Hybrid");
         }
     }
     using (StreamWriter streamWriterAppend = File.AppendText(pathCars))
     {
         if (car.Model == "Audi")
         {
             Audi audi = (Audi)car;
             streamWriterAppend.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}", audi.ID, audi.Model, audi.RegistrationPlate, audi.Seats, audi.Color, audi.Dimensions.A.X, audi.Dimensions.A.Y, audi.Dimensions.B.X, audi.Dimensions.B.Y, "X", "", "", "", "", "", audi.Hybrid);
         }
         else if (car.Model == "BMW")
         {
             BMW bmw = (BMW)car;
             streamWriterAppend.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}", bmw.ID, bmw.Model, bmw.RegistrationPlate, bmw.Seats, bmw.Color, bmw.Dimensions.A.X, bmw.Dimensions.A.Y, bmw.Dimensions.B.X, bmw.Dimensions.B.Y, "X", bmw.HighDomainAirConditioner, bmw.DoubleBass, bmw.Speakers, "", "", "");
         }
         else
         {
             Mercedes mercedes = (Mercedes)car;
             streamWriterAppend.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}", mercedes.ID, mercedes.Model, mercedes.RegistrationPlate, mercedes.Seats, mercedes.Color, mercedes.Dimensions.A.X, mercedes.Dimensions.A.Y, mercedes.Dimensions.B.X, mercedes.Dimensions.B.Y, "X", "", "", "", mercedes.OxygenSystem, mercedes.BulletProofGlass, "");
         }
     }
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var cars = new List <car>
            {
                new Audi(200, "green", "A4"),
                new BMW(25, "silver", "M3")
            };

            foreach (var car in cars)
            {
                car.Repair();
            }

            car bmwZ3  = new BMW(200, "black", "Z3");
            car audiA3 = new Audi(100, "blue", "A3");

            bmwZ3.ShowDetails();
            audiA3.ShowDetails();

            BMW bmwM5 = new BMW(330, "white", "M5");

            bmwM5.ShowDetails();

            car carB = (car)bmwM5;

            carB.ShowDetails();

            Console.ReadKey();
        }
        public void WriteCars(List <Car> cars)
        {
            using (StreamWriter streamWriter = File.CreateText(pathCars))
            {
                streamWriter.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}", "ID", "Model", "Registration Plate", "No.Seats", "Color", "Ax", "Ay", "Bx", "By", "Parked on", "HDAC", "Double Bass", "Speakers", "Oxygen System", "Bullet Proof Glass", "Hybrid");
            }

            using (StreamWriter streamWriterAppend = File.AppendText(pathCars))
            {
                foreach (var car in cars)
                {
                    String line = String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t", car.ID, car.Model, car.RegistrationPlate, car.Seats, car.Color, car.Dimensions.A.X, car.Dimensions.A.Y, car.Dimensions.B.X, car.Dimensions.B.Y, car.ParkedOn);
                    if (car.Model == "Audi")
                    {
                        Audi carAudi = (Audi)car;
                        line += String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", "", "", "", "", "", carAudi.Hybrid);
                    }
                    else if (car.Model == "BMW")
                    {
                        BMW carBMW = (BMW)car;
                        line += String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", carBMW.HighDomainAirConditioner, carBMW.DoubleBass, carBMW.Speakers, "", "", "");
                    }
                    else
                    {
                        Mercedes carMercedes = (Mercedes)car;
                        line += String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", "", "", "", carMercedes.OxygenSystem, carMercedes.BulletProofGlass, "");
                    }
                    streamWriterAppend.WriteLine(line);
                }
            }
        }
Esempio n. 10
0
        public override void Beat(BMW h)
        {
            // faster then i8

            Console.WriteLine(this.GetType().Name +
                              " faster then " + h.GetType().Name);
        }
Esempio n. 11
0
        override public ICar Create()
        {
            // Set all what you need directly thought constructor
            var car = new BMW(2017);

            return(car);
        }
        public ViewResult Edit(int Id)
        {
            BMW game = repository.BMWs
                       .FirstOrDefault(g => g.Id == Id);

            return(View(game));
        }
Esempio n. 13
0
        public ICar GetCar()
        {
            ICar bmw = new BMW();

            Console.WriteLine("Setting BMW model in BMWFactory.");
            bmw.SetModel("i8");
            return(bmw);
        }
        public void Creates_Red_BMW()
        {
            BMW             bmw             = new BMW();
            RedCarDecorator redCarDecorator = new RedCarDecorator(bmw);

            Assert.Equal("BMW is being driven.", redCarDecorator.Drive());
            Assert.Equal("Red", bmw.Color);
        }
Esempio n. 15
0
        public IAuto CreateAuto()
        {
            IAuto auto;

            auto = new BMW("Bemari");

            return(auto);
        }
Esempio n. 16
0
        public void SimpleRegisterTestMethod()
        {
            var container = new Container();

            container.Register(typeof(ICar), typeof(BMW));
            var expected = new BMW();

            Assert.AreEqual(expected.GetType(), container.Resolve(typeof(ICar)).GetType());
        }
 public void ParticipateInRace(BMW myBMW)
 {
     myBMW.Accelerator.Press();
     myBMW.SteeringWheel.TurnLeft();
     myBMW.SteeringWheel.TurnRight();
     myBMW.Accelerator.Release();
     myBMW.Brake.Press();
     myBMW.Brake.Release();
 }
Esempio n. 18
0
        public void FactoryReturnsBMWAsCar()
        {
            Factory <Car> factory = new Factory <Car>();

            var bmw        = new BMW();
            var factorybmw = factory.CreateObject(typeof(BMW));

            Assert.AreEqual(bmw.GetType(), factorybmw.GetType());
            Assert.IsInstanceOfType(bmw, factorybmw.GetType());
        }
Esempio n. 19
0
        public BMW DeleteBMW(int Id)
        {
            BMW dbEntry = context.BMWs.Find(Id);

            if (dbEntry != null)
            {
                context.BMWs.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
        public ActionResult Delete(int Id)
        {
            BMW deletedBMW = repository.DeleteBMW(Id);

            if (deletedBMW != null)
            {
                TempData["message"] = string.Format("Машина \"{0}\" была удалена",
                                                    deletedBMW.Name);
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 21
0
    public void BuyCar(string manufacture)
    {
        if (manufacture == "Mercedes")
        {
            OwnedCars[manufactor] = new Mercedes();
        }

        if (manufacture == "BMW")
        {
            OwnedCars[manufactor] = new BMW();
        }
    }
Esempio n. 22
0
        static void Main(string[] args)
        {
            BMW  bmw  = new BMW("sedan", "red", "BMW", "M5");
            Audi audi = new Audi("sedan", "black", "Audi", "a6");

            bmw.CarStart();
            bmw.AddSpeed(20);
            bmw.AddExtraSpeed(15);
            bmw.DecriseSpeed(25);

            Console.WriteLine(bmw.Make + " current speed is now " + bmw.CurrentSpeed);

            Console.ReadKey();
        }
 public ActionResult Edit(BMW game)
 {
     if (ModelState.IsValid)
     {
         repository.SaveBMW(game);
         TempData["message"] = string.Format("Изменения в Изар-Авто \"{0} {1}\" были сохранены", game.Name, game.Model);
         return(RedirectToAction("Index"));
     }
     else
     {
         // Что-то не так со значениями данных
         return(View(game));
     }
 }
Esempio n. 24
0
        static void Main(string[] args)
        {
            var bmw1 = new BMW("E60", 2010, "WBSNB91010B559959", "Highend", "Lemans Red", "S85V10", 373, 250, 800000, CarType.Sedan);

            bmw1.Print();
            bmw1.Showroom();
            var bmw2 = new BMW("E60", 2010, "WBSNB91010B559969", "Medium", "Metallic Blue", "S85V10", 373, 250, 700000, CarType.Touring);

            bmw2.Print();
            bmw2.Showroom();
            bmw1.Compare(bmw2, "Car 1 and Car 2 ");
            bmw1.Garage();
            bmw2.SimonSynes();

            var mercedes1 = new Mercedes("C63 AMG", 2008, "WBSNB91010B559991", "Highend", "Hot Pink", "M156V8", 336, 250, 1200000, CarType.Touring);

            mercedes1.Print();
            mercedes1.Showroom();
            var mercedes2 = new Mercedes("E63 AMG", 2011, "WBSNB91010B559944", "Extreme", "Aquamarine", "M156V8", 540, 290, 1500000, CarType.Coupe);

            mercedes2.Print();
            mercedes2.Showroom();
            mercedes1.Compare(mercedes2, "Car 1 and Car 2 ");
            mercedes2.Garage();
            mercedes1.Garage();

            var audi1 = new Audi("RS4", 2006, "WBSNB91010B559959", "Lowend", "Military Green", "RS4V8", 253, 250, 650000, CarType.Sedan);

            audi1.Print();
            audi1.Showroom();
            var audi2 = new Audi("RS3", 2008, "WBSNB91010B559969", "Highend", "Pearlescent White", "RS3V8", 253, 250, 800000, CarType.Hatchback);

            audi2.Print();
            audi2.Showroom();
            audi1.Compare(audi2, "Car 1 and Car 2 ");
            audi2.Garage();
            audi1.Garage();

            var volvo1 = new Volvo("XC70", 2005, "WBSNB91010B559478", "Highend", "Matte Black", "D5244T17", 224, 250, 650000, CarType.SUV);

            volvo1.Print();
            volvo1.Showroom();
            var volvo2 = new Volvo("XC90", 2010, "WBSNB91010B559173", "Luxury", "Sun Yellow", "B6304T4", 224, 250, 700000, CarType.SUV);

            volvo2.Print();
            volvo2.Showroom();
            volvo1.Compare(volvo2, "Car 1 and Car 2 ");
            volvo2.Garage();
            volvo1.GeirKjøper();
        }
Esempio n. 25
0
            /*
             * 生产汽车方法
             */

            public Car getCar(String type)
            {
                Car c = null;

                if ("BMW".Equals(type)) //判断顾客是需要那样的汽车
                {
                    c = new BMW();      //生产宝马汽车
                }
                else if ("Benz".Equals(type))
                {
                    c = new Benz(); //生产奔驰
                }
                return(c);
            }
Esempio n. 26
0
        static void ExecuteProblem2FactoryPattern()
        {
            Honda objHonda = new Honda();

            objHonda.GetCarModel();

            BMW objBMW = new BMW();

            objBMW.GetCarModel();

            // If we want to add new class then we need to modify client code also.
            Nano objNano = new Nano();

            objNano.GetCarModel();
        }
Esempio n. 27
0
        public void RegistrationWithLabelsTestMethod()
        {
            var container = new Container();

            container.Register(typeof(ICar), typeof(BMW), "BMW X5");
            container.Register(typeof(ICar), typeof(Toyota), "Toyota Celica");
            var bmwExpected    = new BMW();
            var toyotaExpected = new Toyota();
            var bmwActual      = container.Resolve(typeof(ICar), "BMW X5");
            var toyotaActual   = container.Resolve(typeof(ICar), "Toyota Celica");

            Assert.AreEqual(2, container.Count);
            Assert.AreEqual(bmwExpected.GetType(), bmwActual.GetType());
            Assert.AreEqual(toyotaExpected.GetType(), toyotaActual.GetType());
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            Console.WriteLine("---------- using factory ------------");
            var studentFactory = new StudentFactory();
            var student        = studentFactory.CreateStudent("special");
            var student2       = studentFactory.CreateStudent("normal");

            Console.WriteLine(student.Speak());
            Console.WriteLine(student2.Speak());

            Console.WriteLine("------------- using decorator ----------");
            var juniorWorker = new JuniorWorker();

            juniorWorker.DoWork();
            var seniorWorker = new SeniorWorker(juniorWorker);

            seniorWorker.DoWork();

            Console.WriteLine("-------------- Using singleton -------------");
            // instance will be same when used from anywhere
            GlobalObject global = GlobalObject.GetInstance();

            global.myGlobalList.ForEach(x => Console.WriteLine(x));
            global.myGlobalList.Add("Gaurav");
            global.myGlobalList.Add("Kapoor");
            global.myGlobalList.ForEach(x => Console.WriteLine(x));


            Console.WriteLine("---------------Using Adapter ---------------");
            ILogger outputLogger = new OutputterAdapter();
            var     newSystem    = new MyNewSystem(outputLogger);

            newSystem.Dowork();

            Console.WriteLine("----------------Using Template method -------------");
            Car myCar = new BMW();

            myCar.GetReadyAndDrive();


            Console.WriteLine("----------------Using Observer  -------------");
            Score myScore = new Score();

            myScore.AddObserver(new ScoreObserver());
            myScore.AddObserver(new SuperScoreObserver());
            myScore.Add(5);
            myScore.Subtract(3);
        }
        public void TestInterface()
        {
            BMW carroBMW = new BMW();

            carroBMW.CoisaEspertaBMW = 10;
            carroBMW.Andar();

            ICarro veiculo = new BMW();

            veiculo.Andar();


            Assert.NotNull(veiculo);

            Assert.IsAssignableFrom <IVeiculo>(veiculo);
        }
        static void Main(string[] args)
        {
            List <IDriver> drivers = new List <IDriver>();
            List <ITrack>  tracks  = new List <ITrack>();

            try
            {
                for (int i = 15; i < 75; i += 7)
                {
                    IDriver driver = new Driver("Ivan", i);
                    ITrack  track  = new RaceTrack(i * 1.23, i - 4, "tarmac", i % 2 == 0 ? true : false);

                    drivers.Add(driver);
                    tracks.Add(track);
                }

                IDriver bmwDriver = drivers.FirstOrDefault(d => d.Age > 25 && d.Age < 45);
                IEnumerable <ITrack> openTracks = tracks.Where(t => t.IsOpenAllYear == true);

                ITrack currentTrack = openTracks.FirstOrDefault(t => t.CornersCount > 25);

                ICar bmw = new BMW(2005, "M5", 507, bmwDriver, currentTrack);

                string resultReport = GetInfo(currentTrack, bmw);

                string path = @"D:\RacetrackReport.txt";

                if (!File.Exists(path))
                {
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.WriteLine(resultReport);
                    }
                }
                else
                {
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine(resultReport);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 31
0
 /*
  * 生产汽车方法
  */
 public Car getCar(String type)
 {
     Car c = null;
     if ("BMW".Equals(type)) //判断顾客是需要那样的汽车
     {
         c = new BMW(); //生产宝马汽车
     }
     else if ("Benz".Equals(type))
     {
         c = new Benz(); //生产奔驰
     }
     return c;
 }