public async Task DeleteAsyncTest() { var options = new DbContextOptionsBuilder <GesbancContext>() .UseInMemoryDatabase(databaseName: "gesbancFake") .Options; // Run the test against one instance of the context using (var context = new GesbancContext(options)) { var repo = new EntidadRepository(context); var service = new EntidadService(repo, _mapper); var entities = generateFakeEntidades(); if (context.Entidad.Count() == 0) { foreach (var entity in entities) { await service.PostAsync(entity); } } await service.DeleteAsync(entities[0].Id); } // separated instance to verify. using (var context = new GesbancContext(options)) { Assert.AreEqual(1, context.Entidad.Count()); Assert.AreEqual("Bankia", context.Entidad.Single().Nombre); } }
public async Task GetByIdAsync() { var options = new DbContextOptionsBuilder <GesbancContext>() .UseInMemoryDatabase(databaseName: "gesbancFake") .Options; // Run the test against one instance of the context using (var context = new GesbancContext(options)) { var repo = new EntidadRepository(context); var service = new EntidadService(repo, _mapper); var entities = generateFakeEntidades(); foreach (var entity in entities) { await service.PostAsync(entity); } } // separated instance to verify. using (var context = new GesbancContext(options)) { Assert.AreEqual("123123", context.Entidad.Where(x => x.Id == 1).FirstOrDefault().CodPostal); } }
public async Task PutAsyncTest() { var options = new DbContextOptionsBuilder <GesbancContext>() .UseInMemoryDatabase(databaseName: "gesbancFake") .Options; // Run the test against one instance of the context using (var context = new GesbancContext(options)) { var repo = new EntidadRepository(context); var entity = new EntidadEntity(); var service = new EntidadService(repo, _mapper); if (context.Entidad.Count() == 0) { var ent = generateFakeEntidades().Where(x => x.Id == 1).FirstOrDefault(); entity = await service.PostAsync(ent); } else { entity = context.Entidad.Where(x => x.Id == 1).FirstOrDefault(); } entity.Nombre = "Sabadell3"; await service.PutAsync(entity); } // separated instance to verify. using (var context = new GesbancContext(options)) { Assert.AreEqual(2, context.Entidad.Count()); Assert.AreEqual("Sabadell3", context.Entidad.Where(x => x.Id == 1).FirstOrDefault().Nombre); } }
public EntidadService() { entidadRepositorio = new EntidadRepository(); }