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
18 using Castle
.DynamicProxy
.Generators
;
19 using Castle
.DynamicProxy
.Tests
.Classes
;
20 using NUnit
.Framework
;
23 public class CacheKeyTestCase
26 public void InstanceEquivalence()
28 CacheKey key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, ProxyGenerationOptions
.Default
);
29 CacheKey key2
= new CacheKey(typeof(NonPublicConstructorClass
), null, ProxyGenerationOptions
.Default
);
31 Assert
.AreEqual(key1
, key2
);
33 key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, ProxyGenerationOptions
.Default
);
34 key2
= new CacheKey(typeof(NonPublicConstructorClass
), null, new ProxyGenerationOptions());
36 Assert
.AreEqual(key1
, key2
);
40 public void InstanceEquivalence_WithInterfaces()
42 CacheKey key1
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[0], ProxyGenerationOptions
.Default
);
43 CacheKey key2
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[0], ProxyGenerationOptions
.Default
);
45 Assert
.AreEqual(key1
, key2
);
48 new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] {typeof(IDisposable)}
, ProxyGenerationOptions
.Default
);
50 new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] {typeof(IDisposable)}
, ProxyGenerationOptions
.Default
);
52 Assert
.AreEqual(key1
, key2
);
56 public void DifferentKeys()
58 CacheKey key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, ProxyGenerationOptions
.Default
);
59 CacheKey key2
= new CacheKey(typeof(NonPublicMethodsClass
), null, ProxyGenerationOptions
.Default
);
61 Assert
.AreNotEqual(key1
, key2
);
64 new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] {typeof(IDisposable)}
, ProxyGenerationOptions
.Default
);
66 new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] {typeof(IConvertible)}
, ProxyGenerationOptions
.Default
);
68 Assert
.AreNotEqual(key1
, key2
);
71 new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] {typeof(IDisposable)}
, ProxyGenerationOptions
.Default
);
72 key2
= new CacheKey(typeof(NonPublicMethodsClass
), new Type
[] {typeof(IDisposable)}
, ProxyGenerationOptions
.Default
);
74 Assert
.AreNotEqual(key1
, key2
);
78 public void DifferentOptions()
80 ProxyGenerationOptions options1
= new ProxyGenerationOptions();
81 ProxyGenerationOptions options2
= new ProxyGenerationOptions();
82 options1
.BaseTypeForInterfaceProxy
= typeof(IConvertible
);
83 CacheKey key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, options1
);
84 CacheKey key2
= new CacheKey(typeof(NonPublicConstructorClass
), null, options2
);
86 Assert
.AreNotEqual(key1
, key2
);
88 options1
= new ProxyGenerationOptions();
89 options2
= new ProxyGenerationOptions();
90 options2
.UseSelector
= true;
91 key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, options1
);
92 key2
= new CacheKey(typeof(NonPublicConstructorClass
), null, options2
);
94 Assert
.AreNotEqual(key1
, key2
);
98 public void EquivalentOptions ()
100 ProxyGenerationOptions options1
= new ProxyGenerationOptions ();
101 ProxyGenerationOptions options2
= new ProxyGenerationOptions ();
103 CacheKey key1
= new CacheKey (typeof (NonPublicConstructorClass
), null, options1
);
104 CacheKey key2
= new CacheKey (typeof (NonPublicConstructorClass
), null, options2
);
106 Assert
.AreEqual (key1
, key2
);
110 public void EqualWithProxyForType ()
112 CacheKey key1
= new CacheKey (typeof (NonPublicConstructorClass
), null, null, ProxyGenerationOptions
.Default
);
113 CacheKey key2
= new CacheKey (typeof (NonPublicConstructorClass
), null, null, ProxyGenerationOptions
.Default
);
115 Assert
.AreEqual (key1
, key2
);
117 CacheKey key3
= new CacheKey (null, null, null, ProxyGenerationOptions
.Default
);
118 Assert
.AreNotEqual (key1
, key3
);
119 Assert
.AreNotEqual (key3
, key1
);
121 CacheKey key4
= new CacheKey (null, null, null, ProxyGenerationOptions
.Default
);
122 Assert
.AreEqual (key4
, key3
);
123 Assert
.AreEqual (key3
, key4
);
127 public void EqualNullAndEmptyInterfaces ()
129 CacheKey key1
= new CacheKey (typeof (NonPublicConstructorClass
), null, null, ProxyGenerationOptions
.Default
);
130 CacheKey key2
= new CacheKey (typeof (NonPublicConstructorClass
), null, Type
.EmptyTypes
, ProxyGenerationOptions
.Default
);
132 Assert
.AreEqual (key1
, key2
);
133 Assert
.AreEqual (key2
, key1
);