public PromotionControllerTest() { _dbOptions = new DbContextOptionsBuilder <PromotionContext>() .UseInMemoryDatabase(databaseName: "in-memory") .Options; using (var dbContext = new PromotionContext(_dbOptions)) { dbContext.AddRange(GetFakeCatalog()); dbContext.SaveChanges(); } }
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(); } } }
public virtual void SaveChanges() { _context.SaveChanges(); }