Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / InversionOfControl / Castle.MicroKernel.Tests / GraphTestCase.cs
blobd71c3081e5106f70817d4d2219e3e3491ce01aab
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
17 using Castle.Core;
18 using Castle.Core.Internal;
19 using NUnit.Framework;
21 [TestFixture]
22 public class GraphTestCase
24 private IKernel kernel;
26 [SetUp]
27 public void Init()
29 kernel = new DefaultKernel();
32 [TearDown]
33 public void Dispose()
35 kernel.Dispose();
38 [Test]
39 public void TopologicalSortOnComponents()
41 kernel.AddComponent("a", typeof(A));
42 kernel.AddComponent("b", typeof(B));
43 kernel.AddComponent("c", typeof(C));
45 GraphNode[] nodes = kernel.GraphNodes;
47 Assert.IsNotNull(nodes);
48 Assert.AreEqual(3, nodes.Length);
50 IVertex[] vertices = TopologicalSortAlgo.Sort(nodes);
52 Assert.AreEqual("c", (vertices[0] as ComponentModel).Name);
53 Assert.AreEqual("b", (vertices[1] as ComponentModel).Name);
54 Assert.AreEqual("a", (vertices[2] as ComponentModel).Name);
57 [Test]
58 public void RemoveComponent()
60 kernel.AddComponent("a", typeof(A));
61 kernel.AddComponent("b", typeof(B));
62 kernel.AddComponent("c", typeof(C));
64 Assert.IsFalse(kernel.RemoveComponent("a"));
65 Assert.IsFalse(kernel.RemoveComponent("b"));
67 Assert.IsTrue(kernel.RemoveComponent("c"));
68 Assert.IsTrue(kernel.RemoveComponent("b"));
69 Assert.IsTrue(kernel.RemoveComponent("a"));