为什么 Microsoft Fakes 不创建 ShimFtpWebRequest? [英] Why doesn't Microsoft Fakes create ShimFtpWebRequest?

查看:18
本文介绍了为什么 Microsoft Fakes 不创建 ShimFtpWebRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行以下步骤:

  • 创建默认的 WCF 服务库项目
  • 创建默认的单元测试项目并引用服务库
  • 在单元测试项目中为 System 创建 Fakes 程序集

我期待在 System.4.0.0.0.Fakes 中有一个 ShimFtpWebRequest 类型.那没有.在 System.Net.Fakes 上将 Diagnostics 属性设置为 true 会发出大量警告消息,主要是关于无法生成 存根,包括 FtpWebRequest - 因为这些类是密封的, 是枚举,等等.我没问题,我不在乎存根,我想要的是垫片.没有消息说它无法生成垫片类型.

I was expecting there to be a type ShimFtpWebRequest in System.4.0.0.0.Fakes. There is not. Setting the Diagnostics property to true on System.Net.Fakes emits a huge slew of warning messages mostly talking about failure to generate stubs, including for FtpWebRequest - because those classes are sealed, are enums, and so on. I'm ok with that, and I don't care about stubs, what I want are shims. There is no message saying that it couldn't generate a shim type.

这个问题表明有一些场景是生成的,当 OP 使用它时,但他没有提及有关他如何生成它的任何内容,因为这不是问题的主题.

This question suggests that there are some scenarios were it is generated, as the OP uses it, but he doesn't mention anything about how he generated it, as it isn't the subject of the question.

为什么 Fakes 不生成 ShimFtpWebRequest 类型?

Why doesn't Fakes generate the type ShimFtpWebRequest?

推荐答案

您需要编辑生成的 System.fakes 文件以告诉它生成类.我相信它会自动忽略密封类.

You need to edit the System.fakes file that was generated to tell it to generate the class. I believe it auto ignores sealed classes.

我在测试时遇到了和你一样的问题,但后来我手动告诉它生成它.

I had the same issue as you when I tested, but then I manually told it to generate it.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
    <Assembly Name="System" Version="4.0.0.0"/>
    <ShimGeneration>
        <Add FullName="System.Net.FtpWebRequest"/>
    </ShimGeneration>
</Fakes>

这篇关于为什么 Microsoft Fakes 不创建 ShimFtpWebRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆