Added a few overloads to AddFacility to be consistent with AddComponent.
[castle.git] / InversionOfControl / Castle.MicroKernel.Tests / Pools / PooledLifestyleManagerTestCase.cs
blob2a4eb3d1dff5cf31df1f1be4adef72b3aabbf91d
1 // Copyright 2004-2008 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.MicroKernel.Tests.Pools
17 using System.Collections;
18 using NUnit.Framework;
20 [TestFixture]
21 public class PooledLifestyleManagerTestCase
23 [Test]
24 public void SimpleUsage()
26 IKernel kernel = new DefaultKernel();
27 kernel.AddComponent("a", typeof(PoolableComponent1));
29 PoolableComponent1 inst1 = kernel["a"] as PoolableComponent1;
30 PoolableComponent1 inst2 = kernel["a"] as PoolableComponent1;
32 Assert.IsNotNull(inst1);
33 Assert.IsNotNull(inst2);
35 kernel.ReleaseComponent(inst2);
36 kernel.ReleaseComponent(inst1);
38 PoolableComponent1 other1 = kernel["a"] as PoolableComponent1;
39 PoolableComponent1 other2 = kernel["a"] as PoolableComponent1;
41 Assert.IsNotNull(other1);
42 Assert.IsNotNull(other2);
44 Assert.AreSame(inst1, other1);
45 Assert.AreSame(inst2, other2);
47 kernel.ReleaseComponent(inst2);
48 kernel.ReleaseComponent(inst1);
51 [Test]
52 public void MaxSize()
54 IKernel kernel = new DefaultKernel();
55 kernel.AddComponent("a", typeof(PoolableComponent1));
57 ArrayList instances = new ArrayList();
59 instances.Add(kernel["a"] as PoolableComponent1);
60 instances.Add(kernel["a"] as PoolableComponent1);
61 instances.Add(kernel["a"] as PoolableComponent1);
62 instances.Add(kernel["a"] as PoolableComponent1);
63 instances.Add(kernel["a"] as PoolableComponent1);
65 PoolableComponent1 other1 = kernel["a"] as PoolableComponent1;
67 Assert.IsNotNull(other1);
68 Assert.IsTrue(!instances.Contains(other1));
70 foreach(object inst in instances)
72 kernel.ReleaseComponent(inst);
75 kernel.ReleaseComponent(other1);
77 PoolableComponent1 other2 = kernel["a"] as PoolableComponent1;
78 Assert.IsNotNull(other2);
79 Assert.IsTrue(other1 != other2);
80 Assert.IsTrue(instances.Contains(other2));
82 kernel.ReleaseComponent(other2);