首页 > 解决方案 > .Net Standard 2.0 SQLite.Core 程序集在单元测试中找不到

问题描述

我一直在开发一个 .Net 标准库,它可以进行大量 API 调用,并且其中一些 API 调用需要与 API 提供的 SQLite 数据库进行交叉引用。我正在与 .Net 标准库一起开发一个单元测试项目来测试一切是否正常,以及让一个单元测试项目与库一起增长是很棒的。我写了一段代码,希望能让我轻松访问那个 SQLite DB 但是,我得到了

找不到程序集错误:System.IO.FileNotFoundException:'无法加载文件或程序集'System.Data.SQLite,版本 = 1.0.109.0,文化 = 中性,PublicKeyToken = db937bc2d44ff139'。该系统找不到指定的文件。

我继续安装了 nugets 包

进入我的 .Net 标准库和我的单元测试项目。

尝试创建此类的新实例后,我在单元测试中遇到错误。

我的数据访问类:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace D2DataAccess.SqLite
{
    public class SQLiteDestinyEngine
    {
        private readonly SQLiteConnection Connection;

        public SQLiteDestinyEngine(FileInfo LocalPath)
        {
            var builder = new SQLiteConnectionStringBuilder { DataSource = LocalPath.FullName };
            Connection = new SQLiteConnection(builder.ToString());
        }

        public async Task<Dictionary<long, T>> GetDetailedInformationFromHash<T>(string TableName, params long[] itemHashes)
        {
            return await await Task.Factory.StartNew(async () =>
            {
                var dataSet = new Dictionary<long, T>();
                var query = $"select id, json from '{TableName}' where id in (@hashes)";
                using (var command = new SQLiteCommand(query, Connection))
                {
                    command.Parameters.AddWithValue("@hashes", itemHashes);
                    var reader = await command.ExecuteReaderAsync();
                    while (await reader.ReadAsync())
                    {
                        dataSet.Add(reader.GetInt64(0), JsonConvert.DeserializeObject<T>(reader.GetString(1)));
                    }
                }
                return dataSet;
            }).ConfigureAwait(false);
        }
    }
}

标签: c#sqlite.net-standard

解决方案


推荐阅读