以下是测试实体框架的两个选项。
InMemory database专为不需要严格关系数据库行为的测试而设计。
[TestMethod]
public void Foo_DoesBar_WhenBaz()
{
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseInMemoryDatabase(databaseName: "foo_bar_baz")
.Options;
using (var context = new BloggingContext(options))
{
...
}
}
SQLite in-memory mode当测试需要更多的关系行为时是合适的。
[TestMethod]
public void Foo_DoesBar_WhenBaz()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
try
{
var options = new DbContextOptionsBuilder<BloggingContext>()
.UseSqlite(connection)
.Options;
using (var context = new BloggingContext(options))
{
...
}
}
finally
{
connection.Close();
}
}
谢谢,看起来它现在会做:-) –