Ejemplo n.º 1
0
        public void CanFailCreate2Model()
        {
            ModelRepositoryADO    repo         = new ModelRepositoryADO();
            List <ModelViewModel> modelsBefore = repo.GetAll().ToList();

            Model model = new Model()
            {
                Name   = "TestModel",
                MakeId = 1,
                UserId = "00000000-0000-0000-0000-000002000000"
            };
            var result = repo.Create(model);

            List <ModelViewModel> modelsAfter = repo.GetAll().ToList();

            Assert.AreEqual(modelsBefore.Count, modelsAfter.Count);
        }
Ejemplo n.º 2
0
        public void ADOCanLoadModels()
        {
            var repo   = new ModelRepositoryADO();
            var models = repo.GetAll().ToList();

            Assert.AreEqual(33, models.Count);
            Assert.AreEqual(1, models[0].ModelId);
            Assert.AreEqual("A4", models[0].Name);
        }
Ejemplo n.º 3
0
        public void CanGetAllModels()
        {
            ModelRepositoryADO repo = new ModelRepositoryADO();

            List <ModelViewModel> models = repo.GetAll().ToList();

            Assert.AreEqual("Subaru", models[0].MakeName);
            Assert.AreEqual("Impreza", models[0].ModelName);
            Assert.AreEqual("Ford", models[1].MakeName);
        }
Ejemplo n.º 4
0
        public void CanLoadModels()
        {
            var repo = new ModelRepositoryADO();

            var models = repo.GetAll();

            Assert.AreEqual(10, models.Count);
            Assert.AreEqual("Beetle", models[1].ModelName);
            Assert.AreEqual("Fiesta", models[4].ModelName);
            Assert.AreEqual(5, models[2].ModelID);
        }
Ejemplo n.º 5
0
        public void CanGetAllModels()
        {
            ModelRepositoryADO repo = new ModelRepositoryADO();

            List <Model> Models = repo.GetAll().ToList();

            Assert.AreEqual(5, Models.Count);

            Assert.AreEqual(Models[2].ModelId, 3);
            Assert.AreEqual(Models[2].ModelName, "TLX");
            Assert.AreEqual(Models[2].DateAdded, new DateTime(2020, 7, 2));
        }
Ejemplo n.º 6
0
        public void CanLoadModel()
        {
            var repo = new ModelRepositoryADO();

            var models = repo.GetAll();

            Assert.AreEqual(5, models.Count);

            Assert.AreEqual(1, models[0].ModelID);
            Assert.AreEqual("Aura", models[4].ModelName);
            Assert.AreEqual("2000-03-28", models[2].ModelDateAdded.ToString("yyyy-MM-dd"));
        }
Ejemplo n.º 7
0
        public ActionResult EditVehicle(int id)
        {
            var model            = new EditVehicleViewModel();
            var makeRepo         = new MakeRepositoryADO();
            var modelRepo        = new ModelRepositoryADO();
            var typeRepo         = new TypeRepositoryADO();
            var bodystyleRepo    = new BodyStyleRepositoryADO();
            var transmissionRepo = new TransmissionRepositoryADO();
            var colorRepo        = new ColorRepositoryADO();
            var interiorRepo     = new InteriorRepositoryADO();

            var vehicleRepo = new VehicleRepositoryADO();

            model.Makes         = new SelectList(makeRepo.GetAll(), "MakeID", "MakeName");
            model.Models        = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName");
            model.Types         = new SelectList(modelRepo.GetAll(), "TypeID", "TypeName");
            model.BodyStyles    = new SelectList(modelRepo.GetAll(), "BodyID", "BodyStyleName");
            model.Transmissions = new SelectList(modelRepo.GetAll(), "TransmissionID", "TransmissionType");
            model.Colors        = new SelectList(modelRepo.GetAll(), "ColorID", "ColorName");
            model.Interiors     = new SelectList(modelRepo.GetAll(), "InteriorID", "InteriorColor");

            model.Vehicle = vehicleRepo.GetByID(id);

            return(View(model));
        }
Ejemplo n.º 8
0
        public void CanAddModel()
        {
            var           repo     = new ModelRepositoryADO();
            VehicleModels newModel = new VehicleModels()
            {
                Model    = "Citation",
                MakeID   = 3,
                UserName = "******"
            };

            repo.Add(newModel);
            var models = repo.GetAll();

            Assert.AreEqual(models.Count(), 6);
        }
Ejemplo n.º 9
0
        public ActionResult AddVehicle(AddVehicleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo = new VehicleRepositoryADO();

                try
                {
                    var savePath = Server.MapPath("~/Images");

                    string fileName  = Path.GetFileNameWithoutExtension(model.PictureUpload.FileName);
                    string extension = Path.GetExtension(model.PictureUpload.FileName);

                    var filePath = Path.Combine(savePath, fileName + extension);

                    int counter = 1;
                    while (System.IO.File.Exists(filePath))
                    {
                        filePath = Path.Combine(savePath, fileName + counter.ToString() + extension);
                        counter++;
                    }

                    model.PictureUpload.SaveAs(filePath);
                    model.Vehicle.Picture = Path.GetFileName(filePath);
                    repo.Insert(model.Vehicle);

                    return(RedirectToAction("EditVehicle", "Admin", new { id = model.Vehicle.VehicleID }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var vehicleModel     = new AddVehicleViewModel();
                var makeRepo         = new MakeRepositoryADO();
                var modelRepo        = new ModelRepositoryADO();
                var typeRepo         = new TypeRepositoryADO();
                var bodystyleRepo    = new BodyStyleRepositoryADO();
                var transmissionRepo = new TransmissionRepositoryADO();
                var colorRepo        = new ColorRepositoryADO();
                var interiorRepo     = new InteriorRepositoryADO();

                vehicleModel.Makes         = new SelectList(makeRepo.GetAll(), "MakeID", "MakeName");
                vehicleModel.Models        = new SelectList(modelRepo.GetAll(), "ModelID", "ModelName");
                vehicleModel.Types         = new SelectList(modelRepo.GetAll(), "TypeID", "TypeName");
                vehicleModel.BodyStyles    = new SelectList(modelRepo.GetAll(), "BodyID", "BodyStyleName");
                vehicleModel.Transmissions = new SelectList(modelRepo.GetAll(), "TransmissionID", "TransmissionType");
                vehicleModel.Colors        = new SelectList(modelRepo.GetAll(), "ColorID", "ColorName");
                vehicleModel.Interiors     = new SelectList(modelRepo.GetAll(), "InteriorID", "InteriorColor");

                return(View(vehicleModel));
            }
        }
Ejemplo n.º 10
0
        public void CanAddModel()
        {
            Model model = new Model
            {
                MakeId    = 2,
                ModelName = "TestModel",
                DateAdded = DateTime.Now.Date,
                Addedby   = "*****@*****.**"
            };

            ModelRepositoryADO repo = new ModelRepositoryADO();

            repo.Insert(model);

            List <Model> Models = repo.GetAll().ToList();

            Assert.AreEqual(6, Models.Count);

            Assert.IsNotNull(Models[5].ModelId);
            Assert.AreEqual(2, Models[5].MakeId);
            Assert.AreEqual(model.ModelName, Models[5].ModelName);
            Assert.AreEqual(model.DateAdded, Models[5].DateAdded);
            Assert.AreEqual(model.Addedby, Models[5].Addedby);
        }