当存根简单的只读属性时,RhinoMocks会抛出3个异常。如何在没有例外的情况下做到这一点。
public class ThirdPartyClass
{
public string Name { get; set; }
public ThirdPartyClass(string name)
{
Name = name;
}
}
public interface IWithProperty
{
ThirdPartyClass MyReadonlyProperty { get; }
}
[TestClass]
public class MockedProperty
{
[TestMethod]
public void PropertyTest()
{
IWithProperty withProperty = MockRepository.GenerateStub<IWithProperty>();
// 3 exceptions thrown
withProperty.Stub(wp => wp.MyReadonlyProperty).Return(new ThirdPartyClass("Mocked"));
}
}
在1行中抛出3个异常:
System.MissingMethodException发生Message =类型的构造函数 'Castle.Proxies.ThirdPartyClassProxyc32aba1028c144bb844d190d92ad191a' 未找到。 Source = mscorlib StackTrace: 在System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,Binder binder,Object [] args,CultureInfo culture, Object [] activationAttributes)InnerException:
System.MissingMethodException发生Message =类型的构造函数 'Castle.Proxies.ThirdPartyClassProxyc32aba1028c144bb844d190d92ad191a' 未找到。 Source = mscorlib StackTrace: 在System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,Binder binder,Object [] args,CultureInfo culture, Object [] activationAttributes)InnerException:
System.ArgumentException发生Message =无法实例化代理 类:Test.ThirdPartyClass。找不到 无参数构造函数。参数名称:constructorArguments
Source = Rhino.Mocks ParamName = constructorArguments StackTrace: 在Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(类型classToProxy,Type [] additionalInterfacesToProxy, ProxyGenerationOptions选项,Object [] constructorArguments, IInterceptor []拦截器)InnerException: