Applied Patrick Earl's patch, adding event ModelCreated that allows to re-configure...
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / DefaultViewComponentTreeTests.cs
blob9bb0e2aa57f787b4453d868e3ab9517e582ad2bc
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
17 using System;
18 using Castle.MonoRail.Framework.Services;
19 using Castle.MonoRail.Framework.Tests.Controllers;
20 using Castle.MonoRail.Framework.Tests.Controllers.Clients;
21 using Castle.MonoRail.Framework.Tests.Controllers.Products;
22 using NUnit.Framework;
24 [TestFixture]
25 public class DefaultViewComponentTreeTests
27 #region Member Data
28 private DefaultViewComponentTree _tree;
29 #endregion
31 #region Test Setup and Teardown Methods
32 [SetUp]
33 public void Setup()
35 _tree = new DefaultViewComponentTree();
37 #endregion
39 #region Test Methods
40 [Test]
41 public void AddViewComponent_NewComponent_Works()
43 _tree.AddViewComponent("MyViewComponent", typeof(ViewComponent));
46 [Test]
47 [ExpectedException(typeof(ArgumentException))]
48 public void AddViewComponent_DuplicateComponent_ThrowsException()
50 _tree.AddViewComponent("MyViewComponent", typeof(ViewComponent));
51 _tree.AddViewComponent("MyViewComponent", typeof(ViewComponent));
54 [Test]
55 [ExpectedException(typeof(ArgumentException))]
56 public void AddViewComponent_NonViewComponent_ThrowsException()
58 _tree.AddViewComponent("MyViewComponent", typeof(DefaultViewComponentTree));
61 [Test]
62 [ExpectedException(typeof(ArgumentException))]
63 public void GetViewComponent_MissingComponent_ThrowsException()
65 _tree.GetViewComponent("MissingComponent");
68 [Test]
69 public void GetViewComponent_ExistingComponent_Works()
71 Type type = typeof(ViewComponent);
72 _tree.AddViewComponent("MyViewComponent", type);
73 Assert.AreEqual(type, _tree.GetViewComponent("MyViewComponent"));
76 [Test]
77 public void GetViewComponent_NamedViaAttribute_Works()
79 Type type = typeof(ATestViewComponent);
80 _tree.AddViewComponent("MyViewComponent", type);
81 Assert.AreEqual(type, _tree.GetViewComponent("DifferentName"));
83 #endregion
86 [ViewComponentDetails("DifferentName")]
87 public class ATestViewComponent : ViewComponent