1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.DynamicProxy
.Tests
17 using Castle
.DynamicProxy
.Tests
.Classes
;
18 using Castle
.DynamicProxy
.Tests
.Interceptors
;
19 using Castle
.DynamicProxy
.Tests
.InterClasses
;
20 using NUnit
.Framework
;
23 public class InvocationTestCase
: BasePEVerifyTestCase
26 public void InvocationForConcreteClassProxy()
28 KeepDataInterceptor interceptor
= new KeepDataInterceptor();
30 object proxy
= generator
.CreateClassProxy(typeof(ServiceClass
), interceptor
);
32 ServiceClass instance
= (ServiceClass
) proxy
;
36 Assert
.IsNotNull(interceptor
.Invocation
);
38 Assert
.IsNotNull(interceptor
.Invocation
.Arguments
);
39 Assert
.AreEqual(2, interceptor
.Invocation
.Arguments
.Length
);
40 Assert
.AreEqual(20, interceptor
.Invocation
.Arguments
[0]);
41 Assert
.AreEqual(25, interceptor
.Invocation
.Arguments
[1]);
42 Assert
.AreEqual(20, interceptor
.Invocation
.GetArgumentValue(0));
43 Assert
.AreEqual(25, interceptor
.Invocation
.GetArgumentValue(1));
44 Assert
.AreEqual(45, interceptor
.Invocation
.ReturnValue
);
46 Assert
.IsNotNull(interceptor
.Invocation
.Proxy
);
47 Assert
.IsInstanceOfType(typeof(ServiceClass
), interceptor
.Invocation
.Proxy
);
49 Assert
.IsNotNull(interceptor
.Invocation
.InvocationTarget
);
50 Assert
.IsInstanceOfType(typeof(ServiceClass
), interceptor
.Invocation
.InvocationTarget
);
51 Assert
.IsNotNull(interceptor
.Invocation
.TargetType
);
52 Assert
.AreSame(typeof(ServiceClass
), interceptor
.Invocation
.TargetType
);
54 Assert
.IsNotNull(interceptor
.Invocation
.Method
);
55 Assert
.IsNotNull(interceptor
.Invocation
.MethodInvocationTarget
);
56 Assert
.AreSame(interceptor
.Invocation
.Method
, interceptor
.Invocation
.MethodInvocationTarget
);
60 public void InvocationForInterfaceProxyWithTarget()
62 KeepDataInterceptor interceptor
= new KeepDataInterceptor();
64 object proxy
= generator
.CreateInterfaceProxyWithTarget(
65 typeof(IService
), new ServiceImpl(), interceptor
);
67 IService instance
= (IService
) proxy
;
71 Assert
.IsNotNull(interceptor
.Invocation
);
73 Assert
.IsNotNull(interceptor
.Invocation
.Arguments
);
74 Assert
.AreEqual(2, interceptor
.Invocation
.Arguments
.Length
);
75 Assert
.AreEqual(20, interceptor
.Invocation
.Arguments
[0]);
76 Assert
.AreEqual(25, interceptor
.Invocation
.Arguments
[1]);
77 Assert
.AreEqual(20, interceptor
.Invocation
.GetArgumentValue(0));
78 Assert
.AreEqual(25, interceptor
.Invocation
.GetArgumentValue(1));
79 Assert
.AreEqual(45, interceptor
.Invocation
.ReturnValue
);
81 Assert
.IsNotNull(interceptor
.Invocation
.Proxy
);
82 Assert
.IsNotInstanceOfType(typeof(ServiceImpl
), interceptor
.Invocation
.Proxy
);
84 Assert
.IsNotNull(interceptor
.Invocation
.InvocationTarget
);
85 Assert
.IsInstanceOfType(typeof(ServiceImpl
), interceptor
.Invocation
.InvocationTarget
);
86 Assert
.IsNotNull(interceptor
.Invocation
.TargetType
);
87 Assert
.AreSame(typeof(ServiceImpl
), interceptor
.Invocation
.TargetType
);
89 Assert
.IsNotNull(interceptor
.Invocation
.Method
);
90 Assert
.IsNotNull(interceptor
.Invocation
.MethodInvocationTarget
);
91 Assert
.AreNotSame(interceptor
.Invocation
.Method
, interceptor
.Invocation
.MethodInvocationTarget
);