Moles无法与MVC3(System.Web.Mvc.dll)一起使用。

3
我刚开始研究moles框架,但是从一开始就没有得到好的体验。 由于某些原因,我无法为System.Web.Mvc.dll(v.3)生成moles。
我将尝试逐步解释我的问题:
1. 在刚创建的空解决方案中,我添加了两个项目(Asp.Net MVC 3和Test)。 2. 在测试项目中引用C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\System.Web.Mvc.dll。 3. 在我的测试项目中添加System.Web.Mvc.dll的Moles程序集(在VS2010中)。 4. 构建项目。
在第四步中,我遇到以下错误。
    ------ Build started: Project: SampleMvcApplication.UnitTests, Configuration: Debug Any CPU ------
  Microsoft Moles v0.94.51023.0 - http://research.microsoft.com/moles - .NET v4.0.30319
  Copyright (c) Microsoft Corporation 2007-2010. All rights reserved.

  00:00:00.00> moles
    Moles : info : metadata : ignoring reference D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication.UnitTests\MolesAssemblies\System.Behaviors.dll
    Moles : info : metadata : ignoring reference D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication.UnitTests\MolesAssemblies\System.Moles.dll
    Moles : info : metadata : ignoring reference D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication.UnitTests\MolesAssemblies\System.Web.WebPages.Moles.dll
    Moles : info : configuration : diagnostic is on
    Moles : info : metadata : loading C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll
    Moles : info : compilation : output assembly name: System.Web.Mvc.Moles
Moles : warning : metadata : failed to load module System.Web.Mvc.dll:
Moles : warning : metadata : Inheritance security rules violated by type: 'System.Web.Mvc.CompareAttribute'. Derived types must either match the security accessibility of the base type or be less accessible.
Moles : warning : metadata : Inheritance security rules violated by type: 'System.Web.Mvc.RemoteAttribute'. Derived types must either match the security accessibility of the base type or be less accessible.
Moles : error : code : assembly contains no types or failed to load properly
  00:00:00.20> moles generator 1 errors, 3 warnings
C:\Program Files (x86)\Microsoft Moles\bin\Microsoft.Moles.targets(79,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft Moles\bin\moles.exe" @D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication.UnitTests\obj\Debug\Moles\moles.args" exited with code -1005.
------ Build started: Project: SampleMvcApplication, Configuration: Debug Any CPU ------
  Microsoft Moles v0.94.51023.0 - http://research.microsoft.com/moles - .NET v4.0.30319
  Copyright (c) Microsoft Corporation 2007-2010. All rights reserved.

  00:00:00.00> moles
    Moles : info : metadata : loading C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.dll
    Moles : info : compilation : output assembly name: System.Web.WebPages.Moles
    Moles : info : code : found 71 types
    Moles : info : code : visibility: exported or assembly(System.Web.WebPages.Moles)
    00:00:00.34> code generation
      Moles : info : code : generating code at D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication\obj\Debug\Moles\swwp\m.g.cs
      00:00:00.46> stubs generation
        Moles : info : code : generated 23 stub types
      00:00:00.86> moles generation
        Moles : info : code : generated 33 mole types
    00:00:01.70> compiling
      Moles : info : compilation : Moles assembly: D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication\MolesAssemblies\System.Web.WebPages.Moles.dll
  00:00:02.43> moles generator 0 errors, 0 warnings
  SampleMvcApplication -> D:\Samples\Moles\SampleMVC\SampleMvcApplication\SampleMvcApplication\bin\SampleMvcApplication.dll
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

我调查了所有我能找到的主题,但没有任何有用的帮助(甚至找不到一些有关此问题的好答案和解释。)

以下内容也没有帮助(排除问题类型的解决方案) 无法使用 moles 来模拟 MVC 框架

请建议。 谢谢。


我遇到了同样的问题,我的猜测是在使用Pex对MVC3进行测试时出现了错误。 - Matt Ruwe
2个回答

0

你是否正在使用单元测试?如果是,请检查你的单元测试中是否有MVC 3 dll引用。


不是的。我使用MSTests。Microsoft.VisualStudio.QualityTools.UnitTestFramework,我还将MVC 3 DLL添加到测试项目中。 - user863388

0

您不需要直接添加对moles框架的引用。在创建测试项目并添加对要测试的项目的引用后,右键单击该引用并选择添加Moles程序集。这将在您的测试项目根目录中创建一个.moles文件。现在构建您的测试项目,一切都准备就绪!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接