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
.Views
.Brail
.Tests
18 using System
.Collections
;
21 using System
.Threading
;
23 using NUnit
.Framework
;
26 public class BrailBasicFunctionality
: BaseViewOnlyTestFixture
31 ProcessView_StripRailsExtension("apppath/index.rails");
32 AssertReplyEqualTo("Current apppath is /TestBrail");
36 public void CanUseUrlHelperWithoutPrefix()
38 PropertyBag
["url"] = "blah";
40 ProcessView_StripRailsExtension("home/CanUseUrlHelperWithoutPrefix.rails");
41 AssertReplyEqualTo("Castle.MonoRail.Framework.Helpers.UrlHelper");
45 public void WithNullableDynamicProxyObject()
47 ProxyGenerator generator
= new ProxyGenerator();
48 SimpleProxy proxy
= (SimpleProxy
)generator
.CreateClassProxy(typeof(SimpleProxy
), new StandardInterceptor());
49 PropertyBag
["src"] = proxy
;
50 ProcessView_StripRailsExtension("home/WithNullableDynamicProxyObject.rails");
51 string expected
= @"BarBaz
55 AssertReplyEqualTo(expected
);
59 public void AppPathChangeOnTheFly()
61 string script
= Path
.Combine(ViewSourcePath
, @"Views\AppPath\Index.brail");
62 string newContent
= "new content";
64 using (TextReader read
= File
.OpenText(script
))
66 old
= read
.ReadToEnd();
68 ProcessView_StripRailsExtension("apppath/index.rails");//init brail engine
69 using (TextWriter write
= File
.CreateText(script
))
71 write
.Write(newContent
);
77 ProcessView_StripRailsExtension("apppath/index.rails");
78 AssertReplyEqualTo(newContent
);
82 using (TextWriter write
= File
.CreateText(script
))
90 public void CommonScripts()
92 PropertyBag
["doesExists"] = "foo";
93 ProcessView_StripRailsExtension("home/nullables.rails");
94 string expected
= "\r\nfoo";
95 AssertReplyEqualTo(expected
);
101 ProcessView_StripRailsExtension("home/Empty.rails");
102 string expected
= "";
103 AssertReplyEqualTo(expected
);
107 public void CommonScriptsChangeOnTheFly()
109 string common
= Path
.Combine(ViewSourcePath
, @"Views\CommonScripts\Hello.brail");
111 using (TextReader read
= File
.OpenText(common
))
113 old
= read
.ReadToEnd();
116 def SayHello(name as string):
117 return 'Hello, '+name+'! Modified!'
119 using (TextWriter write
= File
.CreateText(common
))
123 string expected
= "Hello, Ayende! Modified!";
124 // Have to wait for the common scripts recompilation otherwise you get random test failure since the request
125 // sometimes gets there faster you can recompile and it gets the old version.
129 ProcessView_StripRailsExtension("home/hellofromcommon.rails");
130 AssertReplyEqualTo(expected
);
134 using (TextWriter write
= File
.CreateText(common
))
139 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
140 // might get the modified version.
145 public void LayoutsChangeOnTheFly()
147 Layout
= "defaultlayout";
148 string layout
= Path
.Combine(ViewSourcePath
, @"Views\layouts\defaultlayout.brail");
150 using (TextReader read
= File
.OpenText(layout
))
152 old
= read
.ReadToEnd();
154 string newLayout
= @"start modified
157 using (TextWriter write
= File
.CreateText(layout
))
159 write
.Write(newLayout
);
161 string expected
= @"start modified
167 ProcessView_StripRailsExtension("defaultlayout/index.rails");
168 AssertReplyEqualTo(expected
);
172 using (TextWriter write
= File
.CreateText(layout
))
182 public void PreProcessor()
184 this.PropertyBag
.Add("Title", "Ayende");
185 ProcessView_StripRailsExtension("home/preprocessor.rails");
190 <title>AYENDE</title>
193 <li>0</li><li>1</li><li>2</li>
198 AssertReplyEqualTo(expected
);
202 public void CanUseNamespacesFromConfig()
204 BooViewEngine
.Options
.NamespacesToImport
.Add(typeof (TransportType
).Namespace
);
205 string expected
= "Using Udp without namespace, since it is in the web.config\r\n";
206 ProcessView_StripRailsExtension("home/namespacesInConfig.rails");
207 AssertReplyEqualTo(expected
);
211 public void ComplexNestedExpressions()
213 PropertyBag
["title"] = "first";
214 PropertyBag
["pageIndex"] = 5;
215 string expected
= "<a href=\"/TestBrail/customers/list.tdd\" onclick=\"paginate(5)\" >first</a>";
216 ProcessView_StripRailsExtension("home/complexNestedExpressions.rails");
217 AssertReplyEqualTo(expected
);
221 public void ComplexNestedExpressions2()
223 PropertyBag
["title"] = "first";
224 PropertyBag
["pageIndex"] = 5;
226 string expected
= "<a onclick=\"alert(5)\" href=\"/TestBrail/customers/list.tdd?page=5\">first</a>";
227 ProcessView_StripRailsExtension("home/complexNestedExpressions2.rails");
228 AssertReplyEqualTo(expected
);
232 public void Javascript()
234 string expected
= @"<script type='text/javascript'>
235 function paginate(index)
240 ProcessView_StripRailsExtension("home/javascript.rails");
241 AssertReplyEqualTo(expected
);
245 public void Javascript2()
247 string expected
= @"<script type='text/javascript'>
248 function paginate(index)
250 var url = '/TestBrail/customers/list.tdd';
251 var params = 'page='+index+'&isAjax=true';
252 new Ajax.Request(url, {
259 ProcessView_StripRailsExtension("home/javascript2.rails");
260 AssertReplyEqualTo(expected
);
264 public void OutputSubViewInDiv()
266 string expected
= @"<div>
267 Contents for heyhello View
269 ProcessView_StripRailsExtension("home/subview.rails");
270 AssertReplyEqualTo(expected
);
274 public void UsingQuotes()
276 string expected
= "<script type=\"text/javascript\" language=\"javascript\" src=\"/TestBrail/Content/js/datepicker.js\"></script>";
277 ProcessView_StripRailsExtension("home/usingQuotes.rails");
278 AssertReplyEqualTo(expected
);
282 public void DuckOverloadToString()
284 PropertyBag
["birthday"] = new DateTime(1981, 12, 20);
285 ProcessView_StripRailsExtension("home/DuckOverloadToString.rails");
286 AssertReplyEqualTo("20-12-1981");
290 public void NullPropagation()
292 ProcessView_StripRailsExtension("home/NullPropagation.rails");
293 AssertReplyEqualTo("");
296 public class SimpleProxy
298 private string text
= "BarBaz";
299 readonly Hashtable items
= new Hashtable();
301 public virtual object this[string key
]
303 get { return items[key]; }
304 set { items[key] = value; }
307 public virtual string Text
310 set { text = value; }
313 public virtual string Say()