我无法建立Spring.Net的配置,使我可以使用犀牛制品,以生成模拟对象。我认识到,GenerateMock是一个静态方法,所以我需要使用工厂方法的配置,但我不能得到它的工作。这是我使用的配置:

<object id="exampleObject"
        type="Rhino.Mocks.MockRepository, Rhino.Mocks"
factory-method="GenerateMock&amp;lt;MyAssembly.MyInterface>" />

然后,在我的代码(这是一个单元测试)使用:

using (IApplicationContext ctx = ContextRegistry.GetContext()) {....}

,但我得到以下错误消息:

System.Configuration.ConfigurationErrorsException: Error creating context 'spring.root': Could not load type from string value 'MyAssembly.MyInterface'. --->  System.TypeLoadException: Could not load type from string value 'MyAssembly.MyInterface'..

任何想法,为什么我可能会得到错误?

有帮助吗?

解决方案

其实你只指定类型名称,但不是在泛型参数集名称。它应更好地阅读

  factory-method="GenerateMock<[MyNamespace.MyInterface, MyAssembly]>"

请注意方括号引用的全部合格的类型名,你需要抓住最近每晚构建。

全限定名允许CLR定位包含您的类型的组件。否则弹簧会扫描已经加载该类型名称组件。如果您的程序集还没有装,你遇到你所面临的errormessage的。

其他提示

不知道你用,但是这似乎并没有再工作,因为Spring.NET不能正确解释的论据GenerateMock变量NR(其中犀牛的版本嘲笑的 PARAMS ... )。

我花了半天摸不着头脑,并使用以下解决方法:

<object id="Logger" type="Rhino.Mocks.MockRepository, Rhino.Mocks"
            factory-method="GenerateMock&lt;Core.Common.Logging.ILog>" >
      <constructor-arg name="argumentsForConstructor">
            <list element-type="System.Object">             
            </list>
        </constructor-arg>
</object>

我基本上必须明确地传递对象的空数组,使得弹簧将认识到该方法的签名...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top