How to mock ISerializable classes with Moq?
Posted
by asmois
on Stack Overflow
See other posts from Stack Overflow
or by asmois
Published on 2010-04-23T04:38:22Z
Indexed on
2010/04/23
4:43 UTC
Read the original article
Hit count: 1143
Hi there,
I'm completly new to Moq and now trying to create a mock for
System.Assembly
class. I'm using this code:
var mockAssembly = new Mock<Assembly>();
mockAssembly.Setup( x => x.GetTypes() ).Returns( new Type[] {
typeof( Type1 ),
typeof( Type2 )
} );
But when I run tests I get next exception:
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()
Could you reccomend me the right way to mock ISerializable
classes
(like System.Assembly
) with Moq.
Thanks in advance!
© Stack Overflow or respective owner