测试 MobileServiceSQLiteStore 时无法加载文件或程序集“SQLitePCL”

Could not load file or assembly `SQLitePCL` when testing MobileServiceSQLiteStore

单元测试访问 MobileServiceSQLiteStore 时无法加载文件或程序集 SQLitePCL

我一直在尝试按照此处的 Azure 入门说明为移动应用程序构建我的第一个 Microsoft Azure WebAPI https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-how-to-use-client-library/

;移动应用程序利用 MobileServiceSQLiteStore class 的离线同步(推送、拉取)。我遇到的问题是我不断收到 could not load...SQLitePCL 错误。我已经在这上面花了整整 2 天时间,并且阅读了许多类似的堆栈溢出问题,非常相似,但是 none 有助于解决这个问题。

除了简单地克服这个错误(如果有更务实的解决方法)之外,目标是能够编写集成(验收测试)和单元测试来测试我将编写的用于包装 MobileServiceSqlLiteStore 的代码class.

无论我做什么,我都无法让 db.DefineTable<xxDTO>(); 在 windows 控制台或单元测试 运行 中运行 windows。 当我运行以下代码时;

public class Person
{
    public int ID { get; set; }

    [JsonProperty(PropertyName = "text")]
    public string FirstName { get; set; }

    [JsonProperty(PropertyName = "text")]
    public string LastName { get; set; }
}

[Test]
public void can_create_db_and_create_table()
{
    var filename = @"d:\test\testdb.db3";
    SQLitePCL.Batteries.Init();                // this excecutes -> raw.SetProvider((ISQLite3Provider) new SQLite3Provider_esqlite3());
    var db = new MobileServiceSQLiteStore(filename);
    db.DefineTable<Person>();
}

我总是得到以下错误 -> Could not load file or assembly SQLitePCL version 3.8.7.2

重现问题的步骤

  1. 安装 SQLITE (3) 运行时间和工具; sqlite-winrt-3130000.vsix(从https://www.sqlite.org/download.html下载)
  2. 新建 class 项目,.Net 4.5.1
  3. 添加以下包
    • install-package SQLitePCL.bundle_green -version 0.9.3
    • Install-package System.Data.SQLite -version 1.0.102.0
    • Install-package nunit -version 3.4.1
  4. 运行 如上所示的单元测试。

System.Data.SQLite 工作起来很容易,但这与安装在 Android 上的 Sqlite 版本不兼容。即下面的代码 运行s 很容易在 windows;

[Test]
public void prove_we_can_perform_normal_system_data_sqllite_commands()

{
 var path = @"d:\test\provedb2.db";
 File.Create(path).Dispose();
 using (var conn = new System.Data.SQLite.SQLiteConnection($"Data Source={path};Version=3;"))
        {
           conn.Open();
            var cmd = new SQLiteCommand("create table customer (name, tel, add1, add2, id UNIQUE)",conn);
            cmd.ExecuteNonQuery();
        }
}

...但这与 Adroid 和通过 MobileServiceSQLiteStore class.

提供的功能不兼容

如果我使用 dot net Reflector 反编译 MobileServiceSQLiteStore class,我可以确认 MobileServiceSQLiteStore 似乎是 SQLitePCL classes 的包装器。 如果我 运行 下面的单元测试,我会得到与我尝试访问 MobileServiceSQLiteStore class 时相同的错误,这就是为什么我希望应该可以访问这个 class 当不是 运行ning inside/on Android?

[Test]
public void show_MobileServiceSQLiteStore_gives_same_error_as_SQLLitePCL_which_it_wraps()
{

    var path = @"provedb2.db";
    using (var db = new  SQLitePCL.SQLiteConnection($"Data Source={path};Version=3;"))
    {
        var cmd = db.Prepare("create table customer (name, tel, add1, add2, id UNIQUE)");
        cmd.Step();
    }
    // this fails with Unable to load DLL 'sqlite3.dll' >>> aargh!            
}

拥有这样一个怪物神 class 并且无法对其进行单元测试或围绕它创建安全包装器似乎很荒谬?

p.s。我的开发机器是干净的 windows 7 专业版,干净、新鲜且最新 Visual studio 2015,专门为此项目配置。

任何关于我如何在 windows 上 运行 这个 class 的意见或建议都将非常感谢!即如何克服 'Could not load file or assembly SQLitePCL' 错误。

在此先感谢大家。

此致,

艾伦

Azure 移动应用程序 SDK 和工具仅在 Windows 8 或更高版本的开发环境中受支持。您可能能够在 Windows 7 上使用它的某些部分,但不幸的是,我们不支持或测试该配置。

您已经安装了SQLitePCL.bundle_green包,但不是客户端SDK使用的包,我们使用SQLitePCL。这就是为什么软件包安装似乎有效,但客户端库实际上不起作用的原因。

您可以 运行 在 .NET 4.5 控制台应用程序中进行一些客户端库单元测试,请参阅 https://github.com/Azure/azure-mobile-apps-net-client#running-the-tests