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 ManualResetEvent e
= new ManualResetEvent(false);
120 BooViewEngine
.ViewRecompiled
+=delegate
124 using (TextWriter write
= File
.CreateText(common
))
128 string expected
= "Hello, Ayende! Modified!";
129 // Have to wait for the common scripts recompilation otherwise you get random test failure since the request
130 // sometimes gets there faster you can recompile and it gets the old version.
134 ProcessView_StripRailsExtension("home/hellofromcommon.rails");
135 AssertReplyEqualTo(expected
);
139 using (TextWriter write
= File
.CreateText(common
))
144 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
145 // might get the modified version.
150 public void LayoutsChangeOnTheFly()
152 Layout
= "defaultlayout";
153 string layout
= Path
.Combine(ViewSourcePath
, @"Views\layouts\defaultlayout.brail");
155 using (TextReader read
= File
.OpenText(layout
))
157 old
= read
.ReadToEnd();
159 string newLayout
= @"start modified
162 using (TextWriter write
= File
.CreateText(layout
))
164 write
.Write(newLayout
);
166 string expected
= @"start modified
172 ProcessView_StripRailsExtension("defaultlayout/index.rails");
173 AssertReplyEqualTo(expected
);
177 using (TextWriter write
= File
.CreateText(layout
))
187 public void PreProcessor()
189 this.PropertyBag
.Add("Title", "Ayende");
190 ProcessView_StripRailsExtension("home/preprocessor.rails");
195 <title>AYENDE</title>
198 <li>0</li><li>1</li><li>2</li>
203 AssertReplyEqualTo(expected
);
207 public void CanUseNamespacesFromConfig()
209 BooViewEngine
.Options
.NamespacesToImport
.Add(typeof (TransportType
).Namespace
);
210 string expected
= "Using Udp without namespace, since it is in the web.config\r\n";
211 ProcessView_StripRailsExtension("home/namespacesInConfig.rails");
212 AssertReplyEqualTo(expected
);
216 public void ComplexNestedExpressions()
218 PropertyBag
["title"] = "first";
219 PropertyBag
["pageIndex"] = 5;
220 string expected
= "<a href=\"/TestBrail/customers/list.tdd\" onclick=\"paginate(5)\" >first</a>";
221 ProcessView_StripRailsExtension("home/complexNestedExpressions.rails");
222 AssertReplyEqualTo(expected
);
226 public void ComplexNestedExpressions2()
228 PropertyBag
["title"] = "first";
229 PropertyBag
["pageIndex"] = 5;
231 string expected
= "<a onclick=\"alert(5)\" href=\"/TestBrail/customers/list.tdd?page=5\">first</a>";
232 ProcessView_StripRailsExtension("home/complexNestedExpressions2.rails");
233 AssertReplyEqualTo(expected
);
237 public void Javascript()
239 string expected
= @"<script type='text/javascript'>
240 function paginate(index)
245 ProcessView_StripRailsExtension("home/javascript.rails");
246 AssertReplyEqualTo(expected
);
250 public void Javascript2()
252 string expected
= @"<script type='text/javascript'>
253 function paginate(index)
255 var url = '/TestBrail/customers/list.tdd';
256 var params = 'page='+index+'&isAjax=true';
257 new Ajax.Request(url, {
264 ProcessView_StripRailsExtension("home/javascript2.rails");
265 AssertReplyEqualTo(expected
);
269 public void OutputSubViewInDiv()
271 string expected
= @"<div>
272 Contents for heyhello View
274 ProcessView_StripRailsExtension("home/subview.rails");
275 AssertReplyEqualTo(expected
);
279 public void UsingQuotes()
281 string expected
= "<script type=\"text/javascript\" language=\"javascript\" src=\"/TestBrail/Content/js/datepicker.js\"></script>";
282 ProcessView_StripRailsExtension("home/usingQuotes.rails");
283 AssertReplyEqualTo(expected
);
287 public void DuckOverloadToString()
289 PropertyBag
["birthday"] = new DateTime(1981, 12, 20);
290 ProcessView_StripRailsExtension("home/DuckOverloadToString.rails");
291 AssertReplyEqualTo("20-12-1981");
295 public void NullPropagation()
297 ProcessView_StripRailsExtension("home/NullPropagation.rails");
298 AssertReplyEqualTo("");
301 public class SimpleProxy
303 private string text
= "BarBaz";
304 readonly Hashtable items
= new Hashtable();
306 public virtual object this[string key
]
308 get { return items[key]; }
309 set { items[key] = value; }
312 public virtual string Text
315 set { text = value; }
318 public virtual string Say()