使用[HostType(" Moles")时,使用Moq和Moles的TypeInitializationException]

时间:2012-08-13 08:22:11

标签: c# unit-testing moq moles

当使用具有[HostType("Moles")]属性的Moles时,Moq会抛出TypeInitializationException。下面的代码示例和例外。

[TestMethod]
[HostType("Moles")]
public void TestMethod()
{
    var mock = new Mock<IAnything>();
}

例外:

System.TypeInitializationException occurred
  Message=The type initializer for 'Moq.Extensions' threw an exception.
  Source=Moq
  TypeName=Moq.Extensions
  StackTrace:
       at Moq.Extensions.IsMockeable(Type typeToMock)
       at Moq.Mock`1.CheckParameters()
       at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
       at Moq.Mock`1..ctor(MockBehavior behavior)
       at Moq.Mock`1..ctor()
       at BP.DFR.Common.Services.Network.DfrNetworkQueryTests.MyTestMethod()
  InnerException: System.Security.VerificationException
       Message=Operation could destabilize the runtime.
       Source=Moq
       StackTrace:
            at Moq.Extensions..cctor()
       InnerException:

下面的链接表明它可能是一个moq版本问题,但它在3.1和4.0版本中都适用于我。

http://code.google.com/p/moq/issues/detail?id=344

我正在使用VS 2010 Premium SP1。有人解决这个问题吗?

0 个答案:

没有答案