是否可以使用 SQLite.Net-PCL 创建内存数据库?
Is it possible to create an In-memory database using SQLite.Net-PCL?
目前我正在使用 SQLite.Net-PCL 3.1.1 对 Xamarin MvvmCross 应用程序进行单元测试。单元测试项目是一个普通的.NET项目。
所以现在我在嘲笑 MvxSqliteConnectionFactoryBase
public class MockMvxSqliteConnectionFactoryBase : MvxSqliteConnectionFactoryBase
{
#region implemented abstract members of MvxSqliteConnectionFactoryBase
public override string GetPlattformDatabasePath(string databaseName)
{
return "Data Source=:memory:";
}
public override ISQLitePlatform GetCurrentPlatform()
{
return new SQLite.Net.Platform.Generic.SQLitePlatformGeneric();
}
public override ISQLitePlatform GetCurrentPlatform(string key)
{
return new SQLite.Net.Platform.Generic.SQLitePlatformGeneric();
}
#endregion
}
但是数据库不是在内存中创建的,而是在项目的 bin
文件夹中创建的。
我试图像这样初始化 SQLiteConnection
example 但是没有一个构造函数只接受一个字符串。
按照@CL的提示。给了我我改变了方法 GetPlattformDatabasePath:
public override string GetPlattformDatabasePath(string databaseName)
{
return ":memory:";
}
现在我没有看到要在 bin 文件夹中创建的东西,并且不需要在每次单元测试后删除现有数据 运行,因此数据库必须在内存中。
目前我正在使用 SQLite.Net-PCL 3.1.1 对 Xamarin MvvmCross 应用程序进行单元测试。单元测试项目是一个普通的.NET项目。
所以现在我在嘲笑 MvxSqliteConnectionFactoryBase
public class MockMvxSqliteConnectionFactoryBase : MvxSqliteConnectionFactoryBase
{
#region implemented abstract members of MvxSqliteConnectionFactoryBase
public override string GetPlattformDatabasePath(string databaseName)
{
return "Data Source=:memory:";
}
public override ISQLitePlatform GetCurrentPlatform()
{
return new SQLite.Net.Platform.Generic.SQLitePlatformGeneric();
}
public override ISQLitePlatform GetCurrentPlatform(string key)
{
return new SQLite.Net.Platform.Generic.SQLitePlatformGeneric();
}
#endregion
}
但是数据库不是在内存中创建的,而是在项目的 bin
文件夹中创建的。
我试图像这样初始化 SQLiteConnection
example 但是没有一个构造函数只接受一个字符串。
按照@CL的提示。给了我我改变了方法 GetPlattformDatabasePath:
public override string GetPlattformDatabasePath(string databaseName)
{
return ":memory:";
}
现在我没有看到要在 bin 文件夹中创建的东西,并且不需要在每次单元测试后删除现有数据 运行,因此数据库必须在内存中。