我对 Moq 完全陌生,现在正在尝试为
System.Reflection.Assembly
班级创建一个模拟。我正在使用这段代码:
var mockAssembly = new Mock<Assembly>();
mockAssembly.Setup( x => x.GetTypes() ).Returns( new Type[] {
typeof( Type1 ),
typeof( Type2 )
} );
但是当我运行测试时,我得到下一个异常:
System.ArgumentException : The type System.Reflection.Assembly
implements ISerializable, but failed to provide a deserialization
constructor
Stack Trace:
at
Castle.DynamicProxy.Generators.BaseProxyGenerator.VerifyIfBaseImplementsGetObjectData(Type
baseType)
at
Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[]
interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxy(Type
classToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type
classToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options, Object[] constructorArguments,
IInterceptor[] interceptors)
at Moq.Proxy.CastleProxyFactory.CreateProxy[T](ICallInterceptor
interceptor, Type[] interfaces, Object[] arguments)
at Moq.Mock`1.<InitializeInstance>b__0()
at Moq.PexProtector.Invoke(Action action)
at Moq.Mock`1.InitializeInstance()
at Moq.Mock`1.OnGetObject()
at Moq.Mock`1.get_Object()
您能否推荐我使用 Moq模拟ISerializable
课程(例如)的正确方法。System.Reflection.Assembly
提前致谢!