public async Task <JsonResult> GetAll(int skip, int limit, string filter) { await CheckPermission(); var er = new ModelRepository(_logger); var result = new ModelRepository.ModelPaging(); if (filter != null) { result = await er.GetAll(skip, limit, filter); } else { result = await er.GetAll(skip, limit); } return(Json(result)); }
public void DeleteModel_With_ModelTO_Parameter() { //ARRANGE var options = new DbContextOptionsBuilder <FleetManagmentContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FleetManagmentContext(options); IModelRepository modelRepository = new ModelRepository(context); ModelTO model = new ModelTO { Name = "polo", }; ModelTO model2 = new ModelTO { Name = "golf", }; var addedModel = modelRepository.Insert(model); var addedModel2 = modelRepository.Insert(model2); context.SaveChanges(); //List<ModelTO> models = new List<ModelTO>(); var models = modelRepository.GetAll().ToList(); //ACT modelRepository.Remove(addedModel); context.SaveChanges(); models = modelRepository.GetAll().ToList(); //ASSERT Assert.IsNotNull(addedModel); Assert.IsNotNull(addedModel2); Assert.AreNotEqual(0, addedModel.Id); Assert.AreNotEqual(0, addedModel2.Id); Assert.AreEqual("polo", addedModel.Name); Assert.AreEqual("golf", addedModel2.Name); Assert.AreEqual(1, models.Count); }
public void TestMethod1() { var yapartContext = new YapartStoreContext(); var models = new ModelRepository(yapartContext); //Act var result = models.GetAll().ToList(); //Assert var aa = 0; }
public async Task <IEnumerable <Modelo> > GetAll() { _modelRepository = new ModelRepository(); try { return(await _modelRepository.GetAll()); } catch (SqlException sqlex) { throw new LoggedException("Error al consultar la tabla de modelos.", Util.Enums.ExType.Error, sqlex); } catch (Exception ex) { throw new LoggedException("Se produjo un error inesperado al intentar obtener los modelos.", Util.Enums.ExType.Fatal, ex); } }
public HttpResponseMessage GetAll(HttpRequestMessage request) { try { List <Model> Models; using (ModelRepository repository = new ModelRepository()) { Models = repository.GetAll().ToList <Model>(); } return(request.CreateResponse <List <Model> >(HttpStatusCode.OK, Models)); } catch (Exception e) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Não foi possível listar os usuários [" + e.Message + "]")); } }
public ActionResult Edit(int id) { var year = new List <string>(); for (int i = 2000; i <= 2020; i++) { year.Add(i.ToString()); } ViewBag.ModelYear = new SelectList(year); ViewBag.Brands = BR.GetAll(); ViewBag.Categories = CR.GetAll(); ViewBag.Models = MR.GetAll(); ViewBag.SubModels = SMR.GetAll(); return(View(PR.Get(id))); }
public static void TestCanInsert() { var repository = new ModelRepository(); var preModels = getModels(); repository.Insert(preModels); var postModels = repository.GetAll(); var orderdPreModels = preModels.OrderBy(m => m.Name).ThenBy(m => m.DateOfBirth).ThenBy(m => m.Height); var orderedPostModels = postModels.OrderBy(m => m.Name).ThenBy(m => m.DateOfBirth).ThenBy(m => m.Height); Assert.IsTrue(orderdPreModels.Count() == orderedPostModels.Count()); // TODO: better equality comparison Assert.IsTrue(orderdPreModels.ElementAt(0).Name.Equals(orderedPostModels.ElementAt(0).Name)); }
public static void TestCanDelete() { var repository = new ModelRepository (); repository.Insert (getModels ()); var models = repository.GetAll (); var list = new List<long> () { models.First ().Id }; repository.Delete (list); var postCount = repository.CountAll (); var reRead = repository.Get (list); Assert.True (postCount == models.Count () - 1, "Post delete count is incorrect"); Assert.True (reRead.Count () == 0, "Could retrieve the model after deletion"); }
public static void TestCanUpdate() { var repository = new ModelRepository(); repository.Insert(getModels()); var model = repository.GetAll().First(); model.Name = "Updated Model"; repository.Update(model); var updateModel = repository.Get(new List <long> () { model.Id }).First(); Assert.IsTrue(model.Name == updateModel.Name, "Bugger"); }
public void GetAllIncludesAllRelationsOfModel() { var brand = new Brand(); var model = new Model { Brand = brand }; _sut.Add(model); var models = _sut.GetAll(); Assert.That(models, Is.Not.Null); var modelFromDatabase = models.FirstOrDefault(m => m.Id == model.Id); Assert.That(modelFromDatabase.Brand, Is.EqualTo(brand)); }
public static void TestCanDelete() { var repository = new ModelRepository(); repository.Insert(getModels()); var models = repository.GetAll(); var list = new List <long> () { models.First().Id }; repository.Delete(list); var postCount = repository.CountAll(); var reRead = repository.Get(list); Assert.True(postCount == models.Count() - 1, "Post delete count is incorrect"); Assert.True(reRead.Count() == 0, "Could retrieve the model after deletion"); }
public IEnumerable <Model> GetAll() { return(modelRepository.GetAll()); }
public ActionResult getModels(int brandId) { return(Json(MR.GetAll(brandId), JsonRequestBehavior.AllowGet)); }
public static void TestCanUpdate() { var repository = new ModelRepository (); repository.Insert (getModels ()); var model = repository.GetAll ().First (); model.Name = "Updated Model"; repository.Update (model); var updateModel = repository.Get (new List<long> (){model.Id}).First (); Assert.IsTrue (model.Name == updateModel.Name, "Bugger"); }
public void InsercionBusquedaPersonaTest() { // Contexto DbContext dbContext = BuildTestModelContext(); // Repositorio de personas IRepository <Persona> repo = new ModelRepository <Persona>(dbContext); // Creacion { Persona persona = new Persona() { Rut = "130144918", Nombre = "Diego", Paterno = "Urrutia", Materno = "Astorga", Email = "*****@*****.**" }; // Insert into the backend repo.Add(persona); } // Busqueda (exitosa) { Persona persona = repo.GetAll(p => p.Rut.Equals("130144918")).FirstOrDefault(); Assert.NotNull(persona); } // Busqueda (no exitosa) { // Persona persona = repo.GetAll(null).FirstOrDefault(); // Assert.Null(persona); } // Busqueda (no exitosa) { Persona persona = repo.GetAll(p => p.Rut.Equals("132204810")).FirstOrDefault(); Assert.Null(persona); } // Todos { IList <Persona> personas = repo.GetAll(); Assert.NotEmpty(personas); } // Busqueda por nombre (exito) { IList <Persona> personas = repo.GetAll(p => p.Nombre.Equals("Diego")); Assert.NotEmpty(personas); } // Busqueda por nombre (no exito) { IList <Persona> personas = repo.GetAll(p => p.Nombre.Equals("Francisco")); Assert.Empty(personas); } // Busqueda por email { Assert.NotEmpty(repo.GetAll(p => p.Email.Equals("*****@*****.**"))); } // Busqueda por rut y email { Assert.NotNull(repo.GetAll(p => p.Rut.Equals("130144918")).FirstOrDefault()); Assert.NotNull(repo.GetAll(p => p.Email.Equals("*****@*****.**")).FirstOrDefault()); } // Eliminacion { Persona persona = repo.GetById(1); Assert.NotNull(persona); repo.Remove(persona); } // Busqueda no exitosa { Persona persona = repo.GetById(1); Assert.Null(persona); } }
public void InsercionBusquedaEntidadTest() { _output.WriteLine("Starting test .."); DbContext dbContext = BuildTestModelContext(); IRepository <Entidad> repo = new ModelRepository <Entidad>(dbContext); // Test add { // Entidad de prueba Entidad entidad = new Entidad() { Cortito = 12, Largo = 120000000, Valor = 123000, FechaDeAniversario = DateTime.Now, NombreDeLaEntidad = "Este es mi nombre" }; // Debug to output _output.WriteLine(Utils.ToJson(entidad)); // El id tiene que ser 0 Assert.True(entidad.Id == 0, "Id es != de 0"); // Agrego la entidad repo.Add(entidad); // El id tiene que ser 1 (autoincrease) Assert.True(entidad.Id == 1, "Id es != 1"); } // Busqueda de las entidades { IList <Entidad> entidades = repo.GetAll(); // DEBE existir el elemento que se ingreso. Assert.Equal(1, entidades.Count); // El id de la entidad en la base de datos debe ser igual a 1 Assert.True(entidades[0].Id == 1, "Id es != 1"); // Ciclo para obtener todos los elementos en el repositorio foreach (Entidad e in entidades) { Console.WriteLine(Utils.ToJson(e)); } } // Get by id (found) { Entidad entidad = repo.GetById(1); Assert.NotNull(entidad); } // Get by id (not found) { Entidad entidad = repo.GetById(-1); Assert.Null(entidad); } // GetAll with expression { IList <Entidad> entidades = repo.GetAll(e => e.Cortito == 12); Assert.Equal(1, entidades.Count); } //Eliminar entidad (exitosa) { Entidad entidad = repo.GetById(1); Assert.NotNull(entidad); repo.Remove(entidad); } //Eliminar entidad (no exitosa) { Assert.Throws <ArgumentNullException>(() => repo.Remove(null)); } _output.WriteLine("Test ended!"); }
public void ModelRepositoryGetTest() { //Arrange //Init repo IncludeAllMappings.include(); var context = new VehicleContext(); var repository = new Repositorys.Repository(context, new UnitOfWorkFactory(new UnitOfWork(context))); var testRepository = new ModelRepository(repository); var makeRepository = new MakeRepository(repository); //Create maker var vMake = new VehicleMakeDomain() { Name = "ModelRepositoryGetTest", Abrv = "ModelRepositoryGetTest" }; Task.Run(async() => { var response = await makeRepository.Add(vMake); Assert.AreEqual(1, response); }).GetAwaiter().GetResult(); //Get maker IEnumerable <IVehicleMakeDomain> getAllMakers = null; IVehicleMakeDomain targetMaker = null; Task.Run(async() => { getAllMakers = await makeRepository.GetAll(); Assert.IsNotNull(getAllMakers); foreach (var item in getAllMakers) { targetMaker = item; } }).GetAwaiter().GetResult(); //Create model var vModel = new VehicleModelDomain() { Name = "ModelRepositoryGetTest", Abrv = "ModelRepositoryGetTest", VehicleMakeId = targetMaker.VehicleMakeId }; //Add model Task.Run(async() => { var response = await testRepository.Add(vModel); Assert.AreEqual(1, response); }).GetAwaiter().GetResult(); //Get model IEnumerable <IVehicleModelDomain> getAll; IVehicleModelDomain targetModel = null; Task.Run(async() => { getAll = await testRepository.GetAll(); Assert.IsNotNull(getAll); foreach (var item in getAll) { targetModel = item; } var result = await testRepository.Get(targetModel.VehicleModelId); //Assert Assert.AreEqual(targetModel.VehicleModelId, result.VehicleModelId); }).GetAwaiter().GetResult(); }
public ActionResult Index() { return(View(MR.GetAll())); }
public static void TestCanInsert() { var repository = new ModelRepository (); var preModels = getModels (); repository.Insert (preModels); var postModels = repository.GetAll (); var orderdPreModels = preModels.OrderBy (m => m.Name).ThenBy (m => m.DateOfBirth).ThenBy (m => m.Height); var orderedPostModels = postModels.OrderBy (m => m.Name).ThenBy (m => m.DateOfBirth).ThenBy (m => m.Height); Assert.IsTrue (orderdPreModels.Count () == orderedPostModels.Count ()); // TODO: better equality comparison Assert.IsTrue (orderdPreModels.ElementAt (0).Name.Equals (orderedPostModels.ElementAt (0).Name)); }