1 // Copyright 2004-2007 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
.MicroKernel
.Tests
18 using Castle
.Core
.Internal
;
19 using NUnit
.Framework
;
22 public class GraphTestCase
24 private IKernel kernel
;
29 kernel
= new DefaultKernel();
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
);
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"));