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.
14 namespace Castle
.MonoRail
.Views
.Brail
.Tests
17 using System
.Collections
;
19 using System
.Reflection
;
21 using Castle
.MonoRail
.Views
.Brail
.TestSite
.Controllers
;
23 using NUnit
.Framework
;
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
);
38 public void BrailWillCacheSubViewsWhenUsingForwardSlash()
40 ProcessView_StripRailsExtension("subview/useLotsOfSubViews.rails");
41 StringBuilder sb
= new StringBuilder();
42 for (int i
= 0; i
< 50; i
++)
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
++)
56 ProcessView_StripRailsExtension("subview/useLotsOfSubViews.rails");
57 expected
= sb
.ToString();
58 AssertReplyEqualTo(expected
);
62 public void CanCallSubViews()
64 ProcessView_StripRailsExtension("subview/index.rails");
65 string expected
= "View With SubView Content\r\nFrom SubView";
66 AssertReplyEqualTo(expected
);
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
);
78 public void SubViewWithLayout()
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
);
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
);