1 // Copyright 2004-2008 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
.Test
19 using NUnit
.Framework
;
21 using Castle
.DynamicProxy
.Test
.Classes
;
24 /// Summary description for CachedTypeTestCase.
27 public class CachedTypeTestCase
29 private ProxyGenerator _generator
= new ProxyGenerator();
32 public void CachedClassProxies()
34 object proxy
= _generator
.CreateClassProxy(
35 typeof(ServiceClass
), new StandardInterceptor( ) );
37 Assert
.IsNotNull(proxy
);
38 Assert
.IsTrue( typeof(ServiceClass
).IsAssignableFrom( proxy
.GetType() ) );
40 proxy
= _generator
.CreateClassProxy(
41 typeof(ServiceClass
), new StandardInterceptor( ) );
43 Assert
.IsNotNull(proxy
);
44 Assert
.IsTrue( typeof(ServiceClass
).IsAssignableFrom( proxy
.GetType() ) );
48 public void GenerateProxyClassSameNameDistinctNamespace()
50 object proxyA
= _generator
.CreateClassProxy(typeof(Classes
.SimpleClass
),new StandardInterceptor());
51 object proxyB
= _generator
.CreateClassProxy(typeof(Classes
.SubNamespace
.SimpleClass
), new StandardInterceptor());
53 Assert
.IsTrue(proxyA
is Classes
.SimpleClass
,
54 string.Format("Proxy {0} is not a subclass of {1} ", proxyA
.GetType(), typeof(Classes
.SimpleClass
)));
56 Assert
.IsTrue(proxyB
is Classes
.SubNamespace
.SimpleClass
,
57 string.Format("Proxy {0} is not a subclass of {1}", proxyA
.GetType(), typeof(Classes
.SubNamespace
.SimpleClass
)));
61 public void GenerateProxyClassSameNameButOneIsInnerClass()
63 object proxyA
= _generator
.CreateClassProxy(typeof(Classes
.Foo
), new StandardInterceptor());
64 object proxyB
= _generator
.CreateClassProxy(typeof(Classes
.DuplicateNames
.Foo
), new StandardInterceptor());
66 Assert
.IsTrue(proxyA
is Classes
.Foo
,
67 string.Format("Proxy {0} is not a subclass of {1} ", proxyA
.GetType(), typeof(Classes
.Foo
)));
69 Assert
.IsTrue(proxyB
is Classes
.DuplicateNames
.Foo
,
70 string.Format("Proxy {0} is not a subclass of {1}", proxyA
.GetType(), typeof(Classes
.DuplicateNames
.Foo
)));
76 public void GenerateProxyOfGenericType()
79 object proxyA
= _generator
.CreateClassProxy(typeof(genericClass
<int>), new StandardInterceptor());
80 object proxyB
= _generator
.CreateClassProxy(typeof(genericClass
<int>), new StandardInterceptor());
82 Assert
.AreEqual(proxyA
.GetType(), proxyB
.GetType(),"Wrong types for generic classes");
87 public class genericClass
<T
>