1 // Copyright 2004-2007 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
19 using System
.Threading
;
20 using Castle
.MonoRail
.Framework
.Tests
;
21 using NUnit
.Framework
;
24 public class BrailBasicFunctionality
: AbstractTestCase
29 DoGet("apppath/index.rails");
30 AssertReplyEqualTo("Current apppath is ");
34 public void CanUseUrlHelperWithoutPrefix()
36 DoGet("home/CanUseUrlHelperWithoutPrefix.rails");
37 AssertReplyEqualTo("Castle.MonoRail.Framework.Helpers.UrlHelper");
41 public void WithNullableDynamicProxyObject()
43 DoGet("home/WithNullableDynamicProxyObject.rails");
44 string expected
= @"BarBaz
48 AssertReplyEqualTo(expected
);
52 public void AppPathChangeOnTheFly()
54 string script
= Path
.Combine(GetPhysicalDir(), @"Views\AppPath\Index.brail");
55 string newContent
= "new content";
57 using (TextReader read
= File
.OpenText(script
))
59 old
= read
.ReadToEnd();
61 DoGet("apppath/index.rails");//init brail engine
62 using (TextWriter write
= File
.CreateText(script
))
64 write
.Write(newContent
);
70 DoGet("apppath/index.rails");
71 AssertReplyEqualTo(newContent
);
75 using (TextWriter write
= File
.CreateText(script
))
83 public void CommonScripts()
85 DoGet("home/nullables.rails");
86 string expected
= "\r\nfoo";
87 AssertReplyEqualTo(expected
);
93 DoGet("home/Empty.rails");
95 AssertReplyEqualTo(expected
);
99 public void CommonScriptsChangeOnTheFly()
101 string common
= Path
.Combine(GetPhysicalDir(), @"Views\CommonScripts\Hello.brail");
103 using (TextReader read
= File
.OpenText(common
))
105 old
= read
.ReadToEnd();
108 def SayHello(name as string):
109 return 'Hello, '+name+'! Modified!'
111 using (TextWriter write
= File
.CreateText(common
))
115 string expected
= "Hello, Ayende! Modified!";
116 // Have to wait for the common scripts recompilation otherwise you get random test failure since the request
117 // sometimes gets there faster you can recompile and it gets the old version.
121 DoGet("home/hellofromcommon.rails");
122 AssertReplyEqualTo(expected
);
126 using (TextWriter write
= File
.CreateText(common
))
131 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
132 // might get the modified version.
137 public void LayoutsChangeOnTheFly()
139 string layout
= Path
.Combine(GetPhysicalDir(), @"Views\layouts\defaultlayout.brail");
141 using (TextReader read
= File
.OpenText(layout
))
143 old
= read
.ReadToEnd();
145 string newLayout
= @"start modified
148 using (TextWriter write
= File
.CreateText(layout
))
150 write
.Write(newLayout
);
152 string expected
= @"start modified
158 DoGet("defaultlayout/index.rails");
159 AssertReplyEqualTo(expected
);
163 using (TextWriter write
= File
.CreateText(layout
))
173 public void PreProcessor()
175 DoGet("home/preprocessor.rails");
180 <title>AYENDE</title>
183 <li>0</li><li>1</li><li>2</li>
188 AssertReplyEqualTo(expected
);
192 public void CanUseNamespacesFromConfig()
194 string expected
= "Using Udp without namespace, since it is in the web.config\r\n";
195 DoGet("home/namespacesInConfig.rails");
196 AssertReplyEqualTo(expected
);
200 public void ComplexNestedExpressions()
202 string expected
= "<a href=\"/customers/list.rails\" onclick=\"paginate(5)\" >first</a>";
203 DoGet("home/complexNestedExpressions.rails");
204 AssertReplyEqualTo(expected
);
208 public void ComplexNestedExpressions2()
210 string expected
= "<a onclick=\"alert(5)\" href=\"/customers/list.rails?page=5\">first</a>";
211 DoGet("home/complexNestedExpressions2.rails");
212 AssertReplyEqualTo(expected
);
216 public void Javascript()
218 string expected
= @"<script type='text/javascript'>
219 function paginate(index)
224 DoGet("home/javascript.rails");
225 AssertReplyEqualTo(expected
);
229 public void Javascript2()
231 string expected
= @"<script type='text/javascript'>
232 function paginate(index)
234 var url = '/customers/list.rails';
235 var params = 'page='+index+'&isAjax=true';
236 new Ajax.Request(url, {
243 DoGet("home/javascript2.rails");
244 AssertReplyEqualTo(expected
);
248 public void OutputSubViewInDiv()
250 string expected
= @"<div>
251 Contents for heyhello View
253 DoGet("home/subview.rails");
254 AssertReplyEqualTo(expected
);
258 public void UsingQuotes()
260 string expected
= "<script type=\"text/javascript\" language=\"javascript\" src=\"/Content/js/datepicker.js\"></script>";
261 DoGet("home/usingQuotes.rails");
262 AssertReplyEqualTo(expected
);
266 public void DuckOverloadToString()
268 DoGet("home/DuckOverloadToString.rails");
269 AssertReplyEqualTo("20-12-1981");
273 public void NullPropagation()
275 DoGet("home/NullPropagation.rails");
276 AssertReplyIsBlank();