1 // Copyright 2004-2008 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
.Windsor
.Tests
17 using Castle
.MicroKernel
;
18 using Castle
.Windsor
.Configuration
.Interpreters
;
19 using NUnit
.Framework
;
22 public class ChildContainerSupportTestCase
24 private IWindsorContainer container
;
29 container
= new WindsorContainer();
30 container
.AddComponent("A", typeof(A
));
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
;
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
;
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
);
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
);
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
);
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
;
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
;