Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
                }
            }
        }