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
);
47 key1
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] { typeof(IDisposable) }
, ProxyGenerationOptions
.Default
);
48 key2
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] { typeof(IDisposable) }
, ProxyGenerationOptions
.Default
);
50 Assert
.AreEqual(key1
, key2
);
54 public void DifferentKeys()
56 CacheKey key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, ProxyGenerationOptions
.Default
);
57 CacheKey key2
= new CacheKey(typeof(NonPublicMethodsClass
), null, ProxyGenerationOptions
.Default
);
59 Assert
.AreNotEqual(key1
, key2
);
61 key1
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] { typeof(IDisposable) }
, ProxyGenerationOptions
.Default
);
62 key2
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] { typeof(IConvertible) }
, ProxyGenerationOptions
.Default
);
64 Assert
.AreNotEqual(key1
, key2
);
66 key1
= new CacheKey(typeof(NonPublicConstructorClass
), new Type
[] { typeof(IDisposable) }
, ProxyGenerationOptions
.Default
);
67 key2
= new CacheKey(typeof(NonPublicMethodsClass
), new Type
[] { typeof(IDisposable) }
, ProxyGenerationOptions
.Default
);
69 Assert
.AreNotEqual(key1
, key2
);
73 public void DifferentOptions()
75 ProxyGenerationOptions options1
= new ProxyGenerationOptions();
76 ProxyGenerationOptions options2
= new ProxyGenerationOptions();
77 options1
.BaseTypeForInterfaceProxy
= typeof(IConvertible
);
78 CacheKey key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, options1
);
79 CacheKey key2
= new CacheKey(typeof(NonPublicConstructorClass
), null, options2
);
81 Assert
.AreNotEqual(key1
, key2
);
83 options1
= new ProxyGenerationOptions();
84 options2
= new ProxyGenerationOptions();
85 options2
.UseSelector
= true;
86 key1
= new CacheKey(typeof(NonPublicConstructorClass
), null, options1
);
87 key2
= new CacheKey(typeof(NonPublicConstructorClass
), null, options2
);
89 Assert
.AreNotEqual(key1
, key2
);