有没有人让痣正常工作? [英] Has anyone made moles work properly?

查看:113
本文介绍了有没有人让痣正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到有关如何使用mole鼠隔离框架的一致描述,但在该主题上没有发现太多. 到目前为止,我已执行以下操作:

  1. 此处(x86版本)下载痣.
  2. 安装.
  3. 此处的人描述了如何与自定义库一起使用.所以我为自己的图书馆增加了痣的装配.重建后,程序集出现在引用中.
  4. 然后我尝试添加.Moles命名空间的使用并构建该项目,但由于出现了很多错误而失败. MDateTime的示例也不起作用. MDateTime只是没有任何方法.
  5. 考虑到第5次尝试使其无法正常工作,我从系统中将其卸载了.

所以问题是:痣对任何人都起作用吗?如果是的话,您是怎么到达那里的? 我还应该安装pex使其工作吗? 如果我想在msbuild脚本的构建服务器上使用它,该怎么办?我看到他们提到了对msbuild的支持,但是有任何真正的msbuild使用过它的经验吗?

对我来说,在严肃的开发过程中使用它看起来很原始. 也许有人有其他意见?

谢谢.

解决方案

是的,它工作正常.我假设您正在安装v0.94.51023.0.为了使Moles正常运行,您必须做一些事情来设置测试类.这些很快就变成了第二天性-不用担心!

  1. 您必须为要使用Moles的每个组件创建一个模制组件":

    a.右键单击解决方案资源管理器"的参考"节点中的部件,然后选择添加Moles部件". b.如果希望使用.NET Framework程序集,请右键单击引用"节点,然后选择为mscorlib添加Moles程序集".

  2. 参考.CS文件中的Microsoft.Moles.Framework程序集:

    使用Microsoft.Moles.Framework;

  3. 构建项目.这导致将适当的Moles框架引用添加到项目中.正如@Lara所说,如果不添加引用,步骤3将失败.

  4. .li文件中的
  5. 引用摩尔装配体:

    使用MyNamespace.Moles;

  6. 使用[HostType("Moles"]]属性装饰使用Moled类型的测试方法

    [HostType("Moles")]

  7. 通过使用程序集属性来标识.CS文件中使用的整个程序集或单个类型:

    使用MyNameSpace.MyAssemblyName.Moles;

    [assembly:MoledAssemblyType("MyNameSpace.MyAssemblyName")]

    [assembly:MoledType(typeof(MyNameSpace.MyAssemblyName.MyClass))]

在编译测试项目时,Moles复制"moled"程序集,然后将弯路插入到副本中.装配体和类型的命名空间后面附加了".Moles".因此,"MyNameSpace.MyAssembly"变为"MyNameSpace.MyAssembly.Moles".我确定您也熟悉摩尔装配的类型名称的"S"和"M"前缀.如果没有,请参考摩尔参考手册.

I was trying to find a consistent description on how to use moles isolation framework but haven't found much on this topic. So far i did the following:

  1. Download moles from here (x86 version).
  2. Install it.
  3. Here guy describes how to use it with custom library. So i added moles assembly for my own library. After rebuild the assembly appeared in references.
  4. Then i tried to add using of .Moles namespace and build the project but it failed with bunch of errors. Example with MDateTime didn't work either. MDateTime just didn't have any method.
  5. Considering that was 5th failed attempt to get it work i uninstalled it from the system.

So the question: does moles work for anybody at all? If yes how did you get there? Should i also install pex to make it work? What if i want to use it on build server from msbuild script? I saw they mentioned support of msbuild, but has anyone real experience with using it from msbuild?

For me it looks very raw to be used in serious development process. Maybe someone has another opinion?

Thanks.

解决方案

Yes, it works fine. I assume you're installing v0.94.51023.0. For Moles to function properly, you must do a few things, to set up the test class. These quickly become second nature -- don't worry!

  1. You must create a "moled assembly", for each assembly against which you wish to use Moles:

    a. Right-click an assembly in the "References" node of the Solution Explorer, and then select "Add Moles Assembly". b. If you wish to mole a .NET Framework assembly, right-click the References node, and then select "Add Moles Assembly for mscorlib'".

  2. Reference the Microsoft.Moles.Framework assembly in the .CS file:

    using Microsoft.Moles.Framework;

  3. Build the project. This causes the appropriate Moles framework references to be added to the project. As @Lara commented, step 3 will fail, without adding the references.

  4. Reference moled assemblies in the .CS file:

    using MyNamespace.Moles;

  5. Decorate test methods that use Moled types with the [HostType("Moles"] attribute

    [HostType("Moles")]

  6. Identify either an entire assembly or individual types that are used in the .CS file, by using the assembly attributes:

    using MyNameSpace.MyAssemblyName.Moles;

    [assembly: MoledAssemblyType("MyNameSpace.MyAssemblyName")]

    [assembly: MoledType(typeof(MyNameSpace.MyAssemblyName.MyClass))]

When the test project is compiled, Moles copies the "moled" assemblies, and then injects detours into the copy. The namespace of moled assemblies and types are appended with ".Moles". Therefore, "MyNameSpace.MyAssembly" becomes "MyNameSpace.MyAssembly.Moles". I'm sure you are also familiar with the "S" and "M" prefixes to the type names of moled assemblies. If not, please refer to the Moles Reference Manual.

这篇关于有没有人让痣正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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