gpt4 book ai didi

c# - 在单元测试之前加载 Microsoft.SqlServer.Types 的正确方法是什么

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:29 25 4
gpt4 key购买 nike

我正在尝试使用 NUnit 为依赖于 DbGeography.PointFromText(text, 4326) 的代码编写一些单元测试,这需要 Microsoft.SqlServer.Types 被加载。我正在尝试使用以下方式加载它:

[OneTimeSetUp]
public void Startup()
{
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
}

我还尝试在 [Setup] 方法中使用加载它们。当调用使用 DbGeography 的代码时,我以可爱的异常结束:

System.InvalidOperationException : Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.

我确实安装了 Microsoft.SqlServer.Types Nuget 包,它在我的 Web API 2.2 应用程序中运行良好。

最佳答案

您可以在系统上安装这些库,但之后还需要记住在构建服务器和生产环境等上安装。

或者,已成功安装 Microsoft.SqlServer.Types NuGet 并按照说明加载程序集。对于 xunit,我将其包含在 TextFixure 构造函数中。

        SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

此外,发现我需要添加 bindingRedirects:

  <dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>

关于c# - 在单元测试之前加载 Microsoft.SqlServer.Types 的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43771979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com