Support multiple service models for a component. WindsorServiceHostFactory will...
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / BrailSubViewTestCase.cs
blobbfec9e8b9e2b201b0daec16e859e1788df2a30e0
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.
14 namespace Castle.MonoRail.Views.Brail.Tests
16 using System;
17 using System.Collections;
18 using System.IO;
19 using System.Reflection;
20 using System.Text;
21 using Castle.MonoRail.Views.Brail.TestSite.Controllers;
22 using Framework;
23 using NUnit.Framework;
25 [TestFixture]
26 public class BrailSubViewTestCase : BaseViewOnlyTestFixture
28 private void SwitchViewImplementation()
30 Hashtable hashtable1 = (Hashtable) typeof (BooViewEngine).GetField("compilations", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(BooViewEngine);
31 Hashtable hashtable2 = (Hashtable) typeof (BooViewEngine).GetField("constructors", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(BooViewEngine);
32 hashtable1[@"subview\listItem.brail"] = typeof (DummySubView);
33 Type[] typeArray1 = new Type[] {typeof (BooViewEngine), typeof (TextWriter), typeof (IEngineContext), typeof (Controller), typeof (IControllerContext)};
34 hashtable2[typeof (DummySubView)] = typeof (DummySubView).GetConstructor(typeArray1);
37 [Test]
38 public void BrailWillCacheSubViewsWhenUsingForwardSlash()
40 ProcessView_StripRailsExtension("subview/useLotsOfSubViews.rails");
41 StringBuilder sb = new StringBuilder();
42 for (int i = 0; i < 50; i++)
44 sb.Append("real");
46 string expected = sb.ToString();
47 AssertReplyEqualTo(expected);
49 SwitchViewImplementation();
50 // if it was cached, we should get something else
51 sb = new StringBuilder();
52 for (int i = 0; i < 50; i++)
54 sb.Append("dummy");
56 ProcessView_StripRailsExtension("subview/useLotsOfSubViews.rails");
57 expected = sb.ToString();
58 AssertReplyEqualTo(expected);
61 [Test]
62 public void CanCallSubViews()
64 ProcessView_StripRailsExtension("subview/index.rails");
65 string expected = "View With SubView Content\r\nFrom SubView";
66 AssertReplyEqualTo(expected);
69 [Test]
70 public void CanCallSubViewWithPath()
72 ProcessView_StripRailsExtension("subview/SubViewWithPath.rails");
73 string expected = "View With SubView Content\r\nContents for heyhello View";
74 AssertReplyEqualTo(expected);
77 [Test]
78 public void SubViewWithLayout()
80 Layout = "master";
81 ProcessView_StripRailsExtension("subview/index.rails");
82 string expected = "\r\nWelcome!\r\n<p>View With SubView Content\r\nFrom SubView</p>\r\nFooter";
83 AssertReplyEqualTo(expected);
86 [Test]
87 public void SubViewWithParameters()
89 ProcessView_StripRailsExtension("subview/CallSubViewWithParameters.rails");
90 string expected = "View SubView Content With Parameters\r\nMonth: 0\r\nAllow Select: False";
91 AssertReplyEqualTo(expected);