Added container accessor to Castle.Core
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / CacheKeyTestCase.cs
blob0e1c79b0a0b7bead75c2ac50a0d07b965c33ee7b
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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 System;
18 using Castle.DynamicProxy.Generators;
19 using Castle.DynamicProxy.Tests.Classes;
20 using NUnit.Framework;
22 [TestFixture]
23 public class CacheKeyTestCase
25 [Test]
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);
39 [Test]
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 =
48 new CacheKey(typeof(NonPublicConstructorClass), new Type[] {typeof(IDisposable)}, ProxyGenerationOptions.Default);
49 key2 =
50 new CacheKey(typeof(NonPublicConstructorClass), new Type[] {typeof(IDisposable)}, ProxyGenerationOptions.Default);
52 Assert.AreEqual(key1, key2);
55 [Test]
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);
63 key1 =
64 new CacheKey(typeof(NonPublicConstructorClass), new Type[] {typeof(IDisposable)}, ProxyGenerationOptions.Default);
65 key2 =
66 new CacheKey(typeof(NonPublicConstructorClass), new Type[] {typeof(IConvertible)}, ProxyGenerationOptions.Default);
68 Assert.AreNotEqual(key1, key2);
70 key1 =
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);
77 [Test]
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);