I have a project which currently uses a generic repository.
I want to rewrite it and make it use the EF context directly.
For the unit tests I want to use SQLite. In the example here - I see how to provide the DbContextOptions. But how can I provide the second parameter - IOptions, through SQLite?
public ApplicationDbContext(
DbContextOptions options,
IOptions<OperationalStoreOptions> operationalStoreOptions) : base(options, operationalStoreOptions)
{
}
public class SqliteInMemoryItemsControllerTest : ItemsControllerTest, IDisposable
{
private readonly DbConnection _connection;
public SqliteInMemoryItemsControllerTest()
: base(
new DbContextOptionsBuilder<ItemsContext>()
.UseSqlite(CreateInMemoryDatabase())
.Options)
{
_connection = RelationalOptionsExtension.Extract(ContextOptions).Connection;
}
private static DbConnection CreateInMemoryDatabase()
{
var connection = new SqliteConnection("Filename=:memory:");
connection.Open();
return connection;
}
public void Dispose() => _connection.Dispose();
}