예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 public EntidadService()
 {
     entidadRepositorio = new EntidadRepository();
 }