Why doesn't Microsoft Fakes create ShimFtpWebRequest?

▼魔方 西西 提交于 2019-12-11 22:23:51

问题


Performing the following steps:

  • Creating a default WCF Service Library project
  • Creating a default Unit Test project and referencing the service library
  • Creating a Fakes assembly for System in the unit test project

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.

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.

Why doesn't Fakes generate the type ShimFtpWebRequest?


回答1:


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>


来源:https://stackoverflow.com/questions/26914058/why-doesnt-microsoft-fakes-create-shimftpwebrequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!