Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / InversionOfControl / Castle.Windsor.Tests / ChildContainerSupportTestCase.cs
blobe951e39d8d15e9c37af055ebfed10212c4b32aa3
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.Windsor.Tests
17 using Castle.MicroKernel;
18 using Castle.Windsor.Configuration.Interpreters;
19 using NUnit.Framework;
21 [TestFixture]
22 public class ChildContainerSupportTestCase
24 private IWindsorContainer container;
26 [SetUp]
27 public void Init()
29 container = new WindsorContainer();
30 container.AddComponent("A", typeof(A));
33 [Test]
34 public void ResolveAgainstParentContainer()
36 IWindsorContainer childcontainer = new WindsorContainer();
37 container.AddChildContainer(childcontainer);
39 Assert.AreEqual(container, childcontainer.Parent);
41 childcontainer.AddComponent("B", typeof(B));
42 B b = childcontainer["B"] as B;
44 Assert.IsNotNull(b);
47 [Test]
48 public void ResolveAgainstParentContainerWithProperty()
50 IWindsorContainer childcontainer = new WindsorContainer();
51 childcontainer.Parent = container;
53 Assert.AreEqual(container, childcontainer.Parent);
55 childcontainer.AddComponent("B", typeof(B));
56 B b = childcontainer["B"] as B;
58 Assert.IsNotNull(b);
61 [Test]
62 public void AddAndRemoveChildContainer()
64 IWindsorContainer childcontainer = new WindsorContainer();
65 container.AddChildContainer(childcontainer);
66 Assert.AreEqual(container, childcontainer.Parent);
68 container.RemoveChildContainer(childcontainer);
69 Assert.IsNull(childcontainer.Parent);
71 container.AddChildContainer(childcontainer);
72 Assert.AreEqual(container, childcontainer.Parent);
75 [Test]
76 public void AddAndRemoveChildContainerWithProperty()
78 IWindsorContainer childcontainer = new WindsorContainer();
79 childcontainer.Parent = container;
80 Assert.AreEqual(container, childcontainer.Parent);
82 childcontainer.Parent = null;
83 Assert.IsNull(childcontainer.Parent);
85 childcontainer.Parent = container;
86 Assert.AreEqual(container, childcontainer.Parent);
89 [Test]
90 [ExpectedException(typeof(KernelException))]
91 public void AddingToTwoParentContainsThrowsKernelException()
93 IWindsorContainer container3 = new WindsorContainer();
94 IWindsorContainer childcontainer = new WindsorContainer();
95 container.AddChildContainer(childcontainer);
96 container3.AddChildContainer(childcontainer);
99 [Test]
100 [ExpectedException(typeof(KernelException))]
101 public void AddingToTwoParentWithPropertyContainsThrowsKernelException()
103 IWindsorContainer container3 = new WindsorContainer();
104 IWindsorContainer childcontainer = new WindsorContainer();
105 childcontainer.Parent = container;
106 childcontainer.Parent = container3;
109 [Test]
110 public void StartWithParentContainer()
112 IWindsorContainer childcontainer = new WindsorContainer(container, new XmlInterpreter());
114 Assert.AreEqual(container, childcontainer.Parent);
116 childcontainer.AddComponent("B", typeof(B));
117 B b = childcontainer["B"] as B;
119 Assert.IsNotNull(b);
122 public class A
124 public A()
129 public class B
131 public B(A a)