Merged branch back to the trunk. Build is passing with no changes.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Services / ControllerTreeTestCase.cs
blobc33330a38395b313b704bb20e191c7706c0e4439
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.MonoRail.Framework.Tests.Services
17 using System;
18 using Castle.MonoRail.Framework.Services;
19 using Castle.MonoRail.Framework.Tests.Controllers.Clients;
20 using Castle.MonoRail.Framework.Tests.Controllers.Products;
21 using Controllers;
22 using NUnit.Framework;
24 [TestFixture]
25 public class ControllerTreeTestCase
27 [Test]
28 [ExpectedException(typeof(ArgumentNullException))]
29 public void InvalidConstruction()
31 new DefaultControllerTree(null);
34 [Test]
35 public void EmptyArea()
37 DefaultControllerTree tree = new DefaultControllerTree();
38 tree.AddController("", "home", typeof(HomeController));
39 tree.AddController("", "contact", typeof(ContactController));
40 tree.AddController("", "cart", typeof(CartController));
42 Assert.AreEqual( typeof(HomeController), tree.GetController("", "home") );
43 Assert.AreEqual( typeof(ContactController), tree.GetController("", "contact") );
44 Assert.AreEqual( typeof(CartController), tree.GetController("", "cart") );
47 [Test]
48 public void FewAreas()
50 DefaultControllerTree tree = new DefaultControllerTree();
52 tree.AddController("", "home", typeof(HomeController));
53 tree.AddController("", "contact", typeof(ContactController));
54 tree.AddController("", "cart", typeof(CartController));
55 tree.AddController("clients", "home", typeof(ClientHomeController));
56 tree.AddController("clients", "contact", typeof(ClientContactController));
57 tree.AddController("clients", "cart", typeof(ClientCartController));
58 tree.AddController("lists", "home", typeof(ListController));
60 Assert.AreEqual( typeof(HomeController), tree.GetController("", "home") );
61 Assert.AreEqual( typeof(ContactController), tree.GetController("", "contact") );
62 Assert.AreEqual( typeof(CartController), tree.GetController("", "cart") );
64 Assert.AreEqual( typeof(ClientHomeController), tree.GetController("clients", "home") );
65 Assert.AreEqual( typeof(ClientContactController), tree.GetController("clients", "contact") );
66 Assert.AreEqual( typeof(ClientCartController), tree.GetController("clients", "cart") );
68 Assert.AreEqual( typeof(ListController), tree.GetController("lists", "home") );
71 [Test]
72 public void AddingController_RaisesNotifcationEvent()
74 DefaultControllerTree tree = new DefaultControllerTree();
75 bool eventRaised = false;
76 tree.ControllerAdded += delegate { eventRaised = true; };
77 tree.AddController("clients","home",typeof(ClientHomeController));
78 Assert.IsTrue(eventRaised);