Esempio n. 1
0
        private ApplicationDbContext GetInMemoryDbContext()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          // don't raise the error warning us that the in memory db doesn't support transactions
                          .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning))
                          .Options;

            InMemoryTestDbContext = new ApplicationDbContext(options);
            GoodsTestData.Initialize(InMemoryTestDbContext);
            UsersTestData.CreateTestUser(InMemoryTestDbContext);
            return(InMemoryTestDbContext);
        }
Esempio n. 2
0
        public ApplicationDbContext GetSqliteInMemoryDbContext()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseSqlite(connection)
                          .Options;

            InMemorySqliteTestDbContext = new ApplicationDbContext(options);
            InMemorySqliteTestDbContext.Database.EnsureCreated();

            GoodsTestData.Initialize(InMemorySqliteTestDbContext);
            UsersTestData.CreateTestUser(InMemorySqliteTestDbContext);

            return(InMemorySqliteTestDbContext);
        }