Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
 public SecurityRepository(GesbancContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 5
0
 public EntidadRepository(GesbancContext dbContext) : base(dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 6
0
 public BaseRepository(GesbancContext dbContext)
 {
     _dbContext = dbContext;
 }