/// <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(); }
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(); }
/// <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); }
public SqlPostRepository(FanDbContext db) : base(db) { _db = db; }
public IntegrationTestBase() { _loggerFactory = new ServiceCollection().AddLogging().BuildServiceProvider().GetService <ILoggerFactory>(); _db = GetContextWithSqlite(); }
public SqlMediaRepository(FanDbContext db) : base(db) { _db = db; }
public SqlCategoryRepository(FanDbContext db) : base(db) { _db = db; }
public BlogDataTestBase() { _db = GetContextWithSqlite(); // I can either do sqlite in-mem mode or ef core in-mem db }
public DataTestBase() { _db = GetContextWithSqlite(); }