1 // Copyright 2004-2008 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
.MonoRail
.Framework
.Tests
.ViewComponents
18 using Castle
.MonoRail
.Framework
.Services
;
19 using NUnit
.Framework
;
22 public class DefaultViewComponentRegistryTests
24 private DefaultViewComponentRegistry registry
;
29 registry
= new DefaultViewComponentRegistry();
33 public void AddViewComponent_NewComponent_Works()
35 registry
.AddViewComponent("MyViewComponent", typeof(ViewComponent
));
39 [ExpectedException(typeof(MonoRailException
))]
40 public void AddViewComponent_DuplicateComponent_ThrowsException()
42 registry
.AddViewComponent("MyViewComponent", typeof(ViewComponent
));
43 registry
.AddViewComponent("MyViewComponent", typeof(ViewComponent
));
47 [ExpectedException(typeof(MonoRailException
))]
48 public void AddViewComponent_NonViewComponent_ThrowsException()
50 registry
.AddViewComponent("MyViewComponent", typeof(DefaultViewComponentRegistry
));
54 [ExpectedException(typeof(MonoRailException
))]
55 public void GetViewComponent_MissingComponent_ThrowsException()
57 registry
.GetViewComponent("MissingComponent");
61 public void GetViewComponent_ExistingComponent_Works()
63 Type type
= typeof(ViewComponent
);
64 registry
.AddViewComponent("MyViewComponent", type
);
65 Assert
.AreEqual(type
, registry
.GetViewComponent("MyViewComponent"));
69 public void GetViewComponent_ExistingWithoutComponentWithoutSuffixLookup_Works()
71 Type type
= typeof(ViewComponent
);
72 registry
.AddViewComponent("MyView", type
);
73 Assert
.AreEqual(type
, registry
.GetViewComponent("MyView"));
77 public void GetViewComponent_ExistingComponentWithoutSuffix_Works()
79 Type type
= typeof(ViewComponent
);
80 registry
.AddViewComponent("MyViewComponent", type
);
81 Assert
.AreEqual(type
, registry
.GetViewComponent("MyView"));
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