Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / ViewComponents / DefaultViewComponentRegistryTests.cs
blobe442fa752eb678d247396455b88ab1bdf32faa7a
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.MonoRail.Framework.Tests.ViewComponents
17 using System;
18 using Castle.MonoRail.Framework.Services;
19 using NUnit.Framework;
21 [TestFixture]
22 public class DefaultViewComponentRegistryTests
24 private DefaultViewComponentRegistry registry;
26 [SetUp]
27 public void Setup()
29 registry = new DefaultViewComponentRegistry();
32 [Test]
33 public void AddViewComponent_NewComponent_Works()
35 registry.AddViewComponent("MyViewComponent", typeof(ViewComponent));
38 [Test]
39 [ExpectedException(typeof(MonoRailException))]
40 public void AddViewComponent_DuplicateComponent_ThrowsException()
42 registry.AddViewComponent("MyViewComponent", typeof(ViewComponent));
43 registry.AddViewComponent("MyViewComponent", typeof(ViewComponent));
46 [Test]
47 [ExpectedException(typeof(MonoRailException))]
48 public void AddViewComponent_NonViewComponent_ThrowsException()
50 registry.AddViewComponent("MyViewComponent", typeof(DefaultViewComponentRegistry));
53 [Test]
54 [ExpectedException(typeof(MonoRailException))]
55 public void GetViewComponent_MissingComponent_ThrowsException()
57 registry.GetViewComponent("MissingComponent");
60 [Test]
61 public void GetViewComponent_ExistingComponent_Works()
63 Type type = typeof(ViewComponent);
64 registry.AddViewComponent("MyViewComponent", type);
65 Assert.AreEqual(type, registry.GetViewComponent("MyViewComponent"));
68 [Test]
69 public void GetViewComponent_ExistingWithoutComponentWithoutSuffixLookup_Works()
71 Type type = typeof(ViewComponent);
72 registry.AddViewComponent("MyView", type);
73 Assert.AreEqual(type, registry.GetViewComponent("MyView"));
76 [Test]
77 public void GetViewComponent_ExistingComponentWithoutSuffix_Works()
79 Type type = typeof(ViewComponent);
80 registry.AddViewComponent("MyViewComponent", type);
81 Assert.AreEqual(type, registry.GetViewComponent("MyView"));
84 [Test]
85 public void GetViewComponent_NamedViaAttribute_Works()
87 Type type = typeof(ATestViewComponent);
88 registry.AddViewComponent("MyViewComponent", type);
89 Assert.AreEqual(type, registry.GetViewComponent("DifferentName"));
93 [ViewComponentDetails("DifferentName")]
94 public class ATestViewComponent : ViewComponent