Пример #1
0
 /// <summary>
 /// Seed settings, user, post, category and tags.
 /// </summary>
 /// <param name="db"></param>
 private void Seed(FanDbContext db)
 {
     db.Set <Meta>().AddRange(GetSettings());          // settings
     db.Users.Add(GetUser());                          // user
     db.Set <Post>().Add(GetPostWith1Category2Tags()); // post with category and tags
     db.SaveChanges();
 }
Пример #2
0
        public IntegrationTestBase()
        {
            var serviceProvider = new ServiceCollection().AddMemoryCache().AddLogging().BuildServiceProvider();

            _loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            var memCacheOptions = serviceProvider.GetService <IOptions <MemoryDistributedCacheOptions> >();

            _cache = new MemoryDistributedCache(memCacheOptions);

            _db = GetContextWithSqlite();
        }
Пример #3
0
        /// <summary>
        /// Initializes DbContext with SQLite Database Provider in-memory mode with logging to
        /// console and ensure database created.
        /// </summary>
        public IntegrationTestBase()
        {
            var connection = new SqliteConnection()
            {
                ConnectionString = "Data Source=:memory:"
            };

            connection.Open();

            var options = new DbContextOptionsBuilder <FanDbContext>()
                          //.UseLoggerFactory(loggerFactory) // turn on logging to see generated SQL
                          .UseSqlite(connection).Options;

            _db = new FanDbContext(options, loggerFactory);
            _db.Database.EnsureCreated();
        }
        /// <summary>
        /// Returns <see cref="CoreDbContext"/> with SQLite Database Provider in-memory mode.
        /// </summary>
        private FanDbContext GetContextWithSqlite()
        {
            var connection = new SqliteConnection()
            {
                ConnectionString = "Data Source=:memory:"
            };

            connection.Open();

            var builder = new DbContextOptionsBuilder <FanDbContext>();

            builder.UseSqlite(connection);

            var context = new FanDbContext(builder.Options, _loggerFactory);

            context.Database.EnsureCreated();

            return(context);
        }
Пример #5
0
 public SqlPostRepository(FanDbContext db) : base(db)
 {
     _db = db;
 }
 public IntegrationTestBase()
 {
     _loggerFactory = new ServiceCollection().AddLogging().BuildServiceProvider().GetService <ILoggerFactory>();
     _db            = GetContextWithSqlite();
 }
Пример #7
0
 public SqlMediaRepository(FanDbContext db) : base(db)
 {
     _db = db;
 }
Пример #8
0
 public SqlCategoryRepository(FanDbContext db) : base(db)
 {
     _db = db;
 }
Пример #9
0
 public BlogDataTestBase()
 {
     _db = GetContextWithSqlite(); // I can either do sqlite in-mem mode or ef core in-mem db
 }
Пример #10
0
 public DataTestBase()
 {
     _db = GetContextWithSqlite();
 }