【问题标题】:How How to fix fakes generation with StubX509Certificate2如何使用 StubX509Certificate2 修复假货生成
【发布时间】:2020-01-07 22:13:48
【问题描述】:

我无法编译使用 Microsoft fakes 的单元测试项目。尝试这样做时,我会遇到以下错误。

严重性代码描述项目文件行抑制状态 错误 CS0115 'StubX509Certificate2.GetCertHash(HashAlgorithmName)':找不到合适的方法来覆盖 [C:\path\ServerAPI.UnitTest\obj\Debug\Fakes\s\f.csproj] ServerAPI.UnitTest C:\path\ServerAPI.UnitTest \f.cs 137304 活动

我正在使用 Visual Studio 2019(企业版)并且目标是 .NET 4.6.2。我不确定为什么会发生这种情况,并尝试将以下代码添加到 mscorlib.fakes。

<StubGeneration>
<Remove FullName="System.Security.Cryptography"/>
</StubGeneration>

即使删除了虚假的程序集引用和 .fakes 配置文件,我仍然收到此错误。

【问题讨论】:

    标签: c# visual-studio microsoft-fakes shim


    【解决方案1】:

    我遇到了同样的问题。使用以下假文件解决了它:

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="System" Version="4.0.0.0"/>
      <StubGeneration>
        <!-- Prevent the following errors:
        error CS0115: 'StubX509Certificate2.GetCertHash(HashAlgorithmName)': no suitable method found to override
        error CS0115: 'StubX509Certificate2.GetCertHashString(HashAlgorithmName)': no suitable method found to override
        -->
        <Remove Namespace="System.Security.Cryptography"/>
      </StubGeneration>
    </Fakes>
    

    【讨论】:

    • 我必须将它添加到 System.fakesmscorlib.fakes 文件中
    • 这并不完全适合我,但让我朝着正确的方向前进。我也有System.fakesmscorlib.fakes,我的mscorlib.fakes 有: 但是,我对StubGenerationSystem.fakes 一无所知;所以我添加了相同的内容,这为我解决了这个问题。我现在只在测试中使用垫片,而不是任何存根。如果您使用的是 Stubs,这可能对您不起作用。
    猜你喜欢
    • 2014-06-16
    • 2021-04-02
    • 2013-07-18
    • 2011-04-29
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    相关资源
    最近更新 更多