public PromotionControllerTest()
        {
            _dbOptions = new DbContextOptionsBuilder <PromotionContext>()
                         .UseInMemoryDatabase(databaseName: "in-memory")
                         .Options;

            using (var dbContext = new PromotionContext(_dbOptions))
            {
                dbContext.AddRange(GetFakeCatalog());
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var contenxt = new PromotionContext(
                       serviceProvider.GetRequiredService <DbContextOptions <PromotionContext> >()
                       ))
            {
                bool saveChanges = false;

                if (!contenxt.Users.Any())
                {
                    contenxt.Users.AddRange(
                        new User
                    {
                        Name      = "Thalles",
                        Email     = "*****@*****.**",
                        Password  = "******",    // secret
                        CreatedAt = DateTime.Now
                    }
                        );

                    saveChanges = true;
                }

                if (!contenxt.Participants.Any())
                {
                    contenxt.Participants.AddRange(
                        new Participant
                    {
                        Name      = "Thalles Teodoro",
                        Email     = "*****@*****.**",
                        Password  = "******",    // secret
                        Birthdate = new DateTime(1998, 8, 27),
                        Gender    = Gender.M,
                        CreatedAt = DateTime.Now
                    }
                        );

                    saveChanges = true;
                }

                if (saveChanges)
                {
                    contenxt.SaveChanges();
                }
            }
        }
Ejemplo n.º 3
0
 public virtual void SaveChanges()
 {
     _context.SaveChanges();
 }