Removed initial binder support which was replaced with more general approach.
[castle.git] / InversionOfControl / Castle.MicroKernel.Tests / NamingPartsSubSystemTestCase.cs
blob6fe372dbc2ce0cb53a7ecc8f711671c62d3a047e
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.MicroKernel.Tests
17 using Castle.Core;
18 using Castle.MicroKernel.SubSystems.Naming;
19 using Castle.MicroKernel.Tests.ClassComponents;
20 using NUnit.Framework;
22 [TestFixture]
23 public class NamingPartsSubSystemTestCase
25 [Test]
26 public void ComponentQuery()
28 IKernel kernel = new DefaultKernel();
29 kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
31 kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
32 kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
34 ICommon common = kernel["common"] as ICommon;
36 Assert.IsNotNull(common);
37 Assert.AreEqual(typeof(CommonImpl1), common.GetType());
39 common = kernel["common:key1=true"] as ICommon;
41 Assert.IsNotNull(common);
42 Assert.AreEqual(typeof(CommonImpl1), common.GetType());
44 common = kernel["common:secure=true"] as ICommon;
46 Assert.IsNotNull(common);
47 Assert.AreEqual(typeof(CommonImpl2), common.GetType());
50 [Test]
51 public void ComponentGraph()
53 IKernel kernel = new DefaultKernel();
54 kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
56 kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
57 kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
59 GraphNode[] nodes = kernel.GraphNodes;
60 Assert.IsNotNull(nodes);
61 Assert.AreEqual(2, nodes.Length);
64 [Test]
65 public void ServiceLookup()
67 IKernel kernel = new DefaultKernel();
68 kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
70 kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
71 kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
73 ICommon common = kernel[typeof(ICommon)] as ICommon;
75 Assert.IsNotNull(common);
76 Assert.AreEqual(typeof(CommonImpl1), common.GetType());
79 [Test]
80 public void GetAssignableHandlers()
82 IKernel kernel = new DefaultKernel();
83 kernel.AddSubSystem(SubSystemConstants.NamingKey, new NamingPartsSubSystem());
85 kernel.AddComponent("common:key1=true", typeof(ICommon), typeof(CommonImpl1));
86 kernel.AddComponent("common:secure=true", typeof(ICommon), typeof(CommonImpl2));
88 IHandler[] handlers = kernel.GetAssignableHandlers(typeof(ICommon));
90 Assert.IsNotNull(handlers);
91 Assert.AreEqual(2, handlers.Length);