1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
8 using System
.Collections
;
9 using System
.Runtime
.Remoting
.Proxies
;
10 using System
.Runtime
.Remoting
.Messaging
;
11 using System
.Reflection
;
16 /// Summary description for MockInterfaceHandler.
18 public class MockInterfaceHandler
: RealProxy
20 private ICallHandler callHandler
;
22 public MockInterfaceHandler( Type type
, ICallHandler callHandler
) : base( type
)
24 this.callHandler
= callHandler
;
27 public override IMessage
Invoke( IMessage msg
)
29 IMethodCallMessage call
= (IMethodCallMessage
)msg
;
30 IMethodReturnMessage result
= null;
36 object ret
= callHandler
.Call( call
.MethodName
, call
.Args
);
40 MethodInfo info
= call
.MethodBase
as MethodInfo
;
41 Type returnType
= info
.ReturnType
;
43 if( returnType
== typeof( System
.Boolean
) ) ret
= false;
45 if( returnType
== typeof( System
.Byte
) ) ret
= (System
.Byte
)0;
46 if( returnType
== typeof( System
.SByte
) ) ret
= (System
.SByte
)0;
47 if( returnType
== typeof( System
.Decimal
) ) ret
= (System
.Decimal
)0;
48 if( returnType
== typeof( System
.Double
) ) ret
= (System
.Double
)0;
49 if( returnType
== typeof( System
.Single
) ) ret
= (System
.Single
)0;
50 if( returnType
== typeof( System
.Int32
) ) ret
= (System
.Int32
)0;
51 if( returnType
== typeof( System
.UInt32
) ) ret
= (System
.UInt32
)0;
52 if( returnType
== typeof( System
.Int64
) ) ret
= (System
.Int64
)0;
53 if( returnType
== typeof( System
.UInt64
) ) ret
= (System
.UInt64
)0;
54 if( returnType
== typeof( System
.Int16
) ) ret
= (System
.Int16
)0;
55 if( returnType
== typeof( System
.UInt16
) ) ret
= (System
.UInt16
)0;
57 if( returnType
== typeof( System
.Char
) ) ret
= '?';
60 result
= new ReturnMessage( ret
, null, 0, null, call
);
64 result
= new ReturnMessage( e
, call
);