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

            using (var dbContext = new PromotionContext(_dbOptions))
            {
                dbContext.AddRange(GetFakeCatalog());
                dbContext.SaveChanges();
            }
        }
Exemple #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();
                }
            }
        }
Exemple #3
0
 public virtual void SaveChanges()
 {
     _context.SaveChanges();
 }