伪造和.net Framework 4.6.1和系统

时间:2015-12-24 01:53:32

标签: c# .net microsoft-fakes .net-4.6.1

设置OOB默认Visual Studio 2013 Update 5项目时,如果没有设置测试,则使用4.6.1的Target Framework,将Fakes程序集添加到System并设置以下ShimGenerations:

mscorlib.fakes:

<ShimGeneration>
    <Clear/>
    <Add FullName="System.Collections.ReadOnlyCollectionBase"/>
    <Add FullName="System.ApplicationException"/>
    <Add FullName="System.IO.Path"/>
    <Add FullName="System.Security.SecureString"/>
    <Add FullName="Microsoft.Win32.Registry"/>
    <Add FullName="Microsoft.Win32.RegistryKey"/>
    <Add FullName="System.Activator"/>
    <Add FullName="System.Convert"/>
    <Add FullName="System.Version"/>
    <Add FullName="System.StringComparer"/>
    <Add FullName="System.Threading.Thread"/>
</ShimGeneration>

System.fakes:

<ShimGeneration>
    <Clear/>
    <Add FullName="System.Text.RegularExpressions.Regex"/>
    <Add FullName="System.Diagnostics.FileVersionInfo"/>
    <Add FullName="System.Diagnostics.Process"/>
    <Add FullName="System.Net.CookieContainer"/>
    <Add FullName="System.Net.FtpWebRequest"/>
    <Add FullName="System.Net.FtpWebResponse"/>
    <Add FullName="System.Net.IPAddress"/>
    <Add FullName="System.Net.Dns"/>
    <Add FullName="System.Net.Mail.SmtpClient"/>
    <Add FullName="System.Net.Mail.MailMessage"/>
    <Add FullName="System.Net.NetworkInformation.Ping"/>
    <Add FullName="System.Net.NetworkInformation.PingReply"/>
    <Add FullName="System.Net.NetworkInformation.PingException"/>
    <Add FullName="System.Net.HttpWebRequest"/>
    <Add FullName="System.Net.HttpWebResponse"/>
    <Add FullName="System.Net.WebHeaderCollection"/>
    <Add FullName="System.Net.ServicePoint"/>
    <Add FullName="System.Net.NetworkInformation.NetworkInterface"/>
    <Add FullName="System.Net.Sockets.TcpClient"/>
    <Add FullName="System.Net.Sockets.UdpClient"/>
    <Add FullName="System.Net.Sockets.Socket"/>
    <Add FullName="System.Net.WebRequestMethods"/>
    <Add FullName="System.Net.WebRequest"/>
    <Add FullName="System.Uri"/>
</ShimGeneration>

发生以下错误:

  

&#39; System.Net.Sockets.SocketClientAccessPolicyProtocol&#39;已过时:&#39;此API支持.NET Framework基础结构,不能直接在您的代码中使用。&#39;
  [some path \ TestFakes \ UnitTestProject1 \ obj \ Debug \ Fakes \ s \ f.csproj] some path \ TestFakes \ UnitTestProject1 \ f.cs

     

GENERATEFAKES:错误:项目编译失败,退出代码为1

这似乎只发生在此配置中。

我不知道如何解决这个问题,因为我需要拦截大多数.NET框架调用。

1 个答案:

答案 0 :(得分:2)

在这个问题上花了几天后,我发现了以下内容。这是以下类“System.Net.Sockets.Socket”的问题。我发现删除这个填充程序生成,然后删除所有.fakes程序集,然后删除/ Fakes文件夹中的一个.fakes文件并使用“Add Fakes Assembly”对话框重新创建它,重新创建所有.fakes程序集在/ Fakes文件夹中的.fakes文件,并允许代码构建。

由于我不需要伪造“System.Net.Sockets.Socket”,因此这是成功构建和重新运行单元测试的可接受解决方案。这肯定是这个类和Fakes框架的一个问题。

我发现Fakes框架很好但需要更好的支持。像这样的事情很难排除故障并需要改进。对我来说,上述不是一个可接受的整体解决方案。我发现,如果MS能够在上述问题上提供更好的反馈和更详细的解决方案,那么它的解决方案会更简单。人们不应该花几天时间查看日志,在网上进行研究并测试一个简单的消息,例如“此类不支持Shim Generation”就足够了。