protected DbContextTestSetup() { DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); string connectionString = new SqliteConnectionStringBuilder { DataSource = "file::memory:", Cache = SqliteCacheMode.Shared }.ToString(); _connection = new SqliteConnection(connectionString); _connection.Open(); builder.EnableSensitiveDataLogging(); builder.UseSqlite(_connection); _context = new BmtDbContext(builder.Options); _context.Database.EnsureCreated(); InitContent.PopulateDb(_context); }
public Startup(IConfiguration configuration) { Configuration = configuration; // In-memory sqlite requires an open connection throughout the whole lifetime of the database _sqlConnectionString = Configuration.GetSection("Database").GetValue <string>("ConnectionString"); if (string.IsNullOrEmpty(_sqlConnectionString)) { DbContextOptionsBuilder <BmtDbContext> builder = new DbContextOptionsBuilder <BmtDbContext>(); string connectionString = new SqliteConnectionStringBuilder { DataSource = "file::memory:", Cache = SqliteCacheMode.Shared }.ToString(); _connection = new SqliteConnection(connectionString); _connection.Open(); builder.UseSqlite(_connection); using (BmtDbContext context = new BmtDbContext(builder.Options)) { context.Database.EnsureCreated(); InitContent.PopulateDb(context); } } }