在HttpWebRequest中将Moles用于TDD [英] Using Moles for TDD with HttpWebRequest

查看:85
本文介绍了在HttpWebRequest中将Moles用于TDD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将VS2010与SP1一起使用(也在同一台计算机上安装了VS2012).痣1.0 该项目正在使用.NET 4 我将moles程序集添加到system.dll,并在编译时出现以下错误

I am using VS2010 with SP1 (also have VS2012 installed on the same machine). Moles 1.0 The project is using .NET 4 I added moles assembly to system.dll and get the following error on compile

错误46类型或名称空间名称'IReadOnlyList'在名称空间'System.Collections.Generic'中不存在(您是否缺少程序集引用?)[C:\ Test \ obj \ Debug \ Moles \ s \ mg csproj] C:\ Test \ mgcs测试

Error 46 The type or namespace name 'IReadOnlyList' does not exist in the namespace 'System.Collections.Generic' (are you missing an assembly reference?) [C:\Test\obj\Debug\Moles\s\m.g.csproj] C:\Test\m.g.cs Test

IReadOnlyList .NET 4.5.

IReadOnlyList .NET 4.5 as far as I know.

还有其他人遇到这个问题吗?

Anyone else got this issue?

推荐答案

更新的解决方案 我能够让Pex在安装了.Net Framework 4.5的VS 2010中运行.也许其他人已经解释说这是解决方案,但是我的问题(对Moles和Pex来说是新问题)是许多解释都含糊不清.感谢这些帖子的作者,因为它们使我朝着正确的方向前进:

Updated Solution I was able to get Pex to run in VS 2010 with .Net Framework 4.5 installed. Maybe others have explained that this is the solution but my issue (being new to Moles and Pex) is that many of the explanations were vague. Thanks to the author of these posts because they got me headed in the right direction:

http://feherzsolt.wordpress.com/2013/02/13/moles-and-net-4-5/

http://www.daedtech.com/using-moles-与系统组装

因此解决方案是在测试项目中以与Pex创建yourAssemblyUnderTest.moles文件相同的级别创建一个新的.moles文件(System.moles),并将以下内容添加到该文件中.

So the solution is to create a new .moles file (System.moles) in the test project at the same level that Pex created the yourAssemblyUnderTest.moles file and add the following to the file.

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
    <Assembly Name="System" ReflectionOnly="true" />
</Moles>

您可能需要清理(或手动删除obj文件夹中的内容)并重建,但是此解决方案对我有用.我还注意到,第一个构建将报告构建错误,但在后续的构建中这些错误将消失.

You may have to clean (or manually delete the obj folder contents) and rebuild but this solution worked for me. I also noticed that the first build would report build errors, but the errors would go away on subsequent builds.

替代解决方案 我知道这不是 THE 解决方案,但这是一种(较差的)解决方法,无法让Pex运行...而且这个时间太长,无法发表评论.如果有人知道如何使PEX在带有4.5 .Net Framework的计算机上运行,​​请响应.

Alternative Solution I know this isn't THE solution but it is a (poor) workaround that allows Pex to run...plus this was too long for a comment. If anyone knows how to get PEX to run on a machine with the 4.5 .Net Framework PLEASE respond.

这是我的情况.我有一台装有.Net Framework 4.5的计算机,并且已安装Visual Studio 2010和2012.我安装了Pex(en_visual_studio_2010_pex_0.94.51023.0_power_tools_x64_598803.exe),可以在针对.Net Framework 4.0的VS 2010项目中运行Pex.我可以运行Pex并发现问题...但是一旦将问题升级到单元测试,由于以下构建错误,单元测试项目将无法编译

This was my scenario. I have a machine with the .Net Framework 4.5 and I have Visual Studio 2010 and 2012 installed. I installed Pex (en_visual_studio_2010_pex_0.94.51023.0_power_tools_x64_598803.exe) and could run Pex in a VS 2010 project that was targeting .Net Framework 4.0. I could run Pex and it identified issues...but once I promoted issues to Unit Tests the unit test project wouldn't compile because of the following build error

The type or namespace name 'IReadOnlyList' does not exist in the namespace 'System.Collections.Generic' (are you missing an assembly reference?)

经过大量搜索,并了解到Pex或Moles用4.0版本替换了4.5 .Net Framework程序集后,我决定卸载4.5,安装4.0,然后尝试一下.在4.0上运行可以很好地工作,我不需要定义Mole类型的过滤器即可使其工作.然后,我尝试再次尝试升级到4.5 Framework ...但是可悲的是,我最终回到了IReadOnlyList名称空间问题的开头.

After much searching, and reading that Pex or Moles was replacing 4.5 .Net Framework assemblies with 4.0 versions I decided to uninstall 4.5, install 4.0, and give it a try. Running on 4.0 works just fine and I didn't need to define Mole type filters to get it to work. Then I tried tried to upgrade to the 4.5 Framework again...but sadly I end up right back where I started with the IReadOnlyList namespace issue.

这篇关于在HttpWebRequest中将Moles用于TDD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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