Minor style changes
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / BrailBasicFunctionality.cs
blobec188d43d2274e32cfc3940d3a710c714ca2245e
1 // Copyright 2004-2007 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.
15 namespace Castle.MonoRail.Views.Brail.Tests
17 using System;
18 using System.IO;
19 using System.Threading;
20 using Castle.MonoRail.Framework.Tests;
21 using NUnit.Framework;
23 [TestFixture]
24 public class BrailBasicFunctionality : AbstractTestCase
26 [Test]
27 public void AppPath()
29 DoGet("apppath/index.rails");
30 AssertReplyEqualTo("Current apppath is ");
33 [Test]
34 public void CanUseUrlHelperWithoutPrefix()
36 DoGet("home/CanUseUrlHelperWithoutPrefix.rails");
37 AssertReplyEqualTo("Castle.MonoRail.Framework.Helpers.UrlHelper");
40 [Test]
41 public void WithNullableDynamicProxyObject()
43 DoGet("home/WithNullableDynamicProxyObject.rails");
44 string expected = @"BarBaz
45 foo
46 what?
47 there";
48 AssertReplyEqualTo(expected);
51 [Test]
52 public void AppPathChangeOnTheFly()
54 string script = Path.Combine(GetPhysicalDir(), @"Views\AppPath\Index.brail");
55 string newContent = "new content";
56 string old;
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);
65 write.Flush();
67 Thread.Sleep(1000);
68 try
70 DoGet("apppath/index.rails");
71 AssertReplyEqualTo(newContent);
73 finally
75 using (TextWriter write = File.CreateText(script))
77 write.Write(old);
82 [Test]
83 public void CommonScripts()
85 DoGet("home/nullables.rails");
86 string expected = "\r\nfoo";
87 AssertReplyEqualTo(expected);
90 [Test]
91 public void Empty()
93 DoGet("home/Empty.rails");
94 string expected = "";
95 AssertReplyEqualTo(expected);
98 [Test]
99 public void CommonScriptsChangeOnTheFly()
101 string common = Path.Combine(GetPhysicalDir(), @"Views\CommonScripts\Hello.brail");
102 string old;
103 using (TextReader read = File.OpenText(common))
105 old = read.ReadToEnd();
107 string @new = @"
108 def SayHello(name as string):
109 return 'Hello, '+name+'! Modified!'
110 end";
111 using (TextWriter write = File.CreateText(common))
113 write.Write(@new);
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.
118 Thread.Sleep(500);
121 DoGet("home/hellofromcommon.rails");
122 AssertReplyEqualTo(expected);
124 finally
126 using (TextWriter write = File.CreateText(common))
128 write.Write(old);
131 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
132 // might get the modified version.
133 Thread.Sleep(500);
136 [Test]
137 public void LayoutsChangeOnTheFly()
139 string layout = Path.Combine(GetPhysicalDir(), @"Views\layouts\defaultlayout.brail");
140 string old;
141 using (TextReader read = File.OpenText(layout))
143 old = read.ReadToEnd();
145 string newLayout = @"start modified
146 ${ChildOutput}
147 end";
148 using (TextWriter write = File.CreateText(layout))
150 write.Write(newLayout);
152 string expected = @"start modified
153 content
154 end";
155 Thread.Sleep(500);
158 DoGet("defaultlayout/index.rails");
159 AssertReplyEqualTo(expected);
161 finally
163 using (TextWriter write = File.CreateText(layout))
165 write.Write(old);
168 Thread.Sleep(500);
172 [Test]
173 public void PreProcessor()
175 DoGet("home/preprocessor.rails");
176 string expected =
178 <html>
179 <body>
180 <title>AYENDE</title>
181 <body>
182 <ul>
183 <li>0</li><li>1</li><li>2</li>
184 </ul>
185 </body>
186 </html>
188 AssertReplyEqualTo(expected);
191 [Test]
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);
199 [Test]
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);
207 [Test]
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);
215 [Test]
216 public void Javascript()
218 string expected = @"<script type='text/javascript'>
219 function paginate(index)
221 alert(index);
223 </script>";;
224 DoGet("home/javascript.rails");
225 AssertReplyEqualTo(expected);
228 [Test]
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, {
237 method: 'get',
238 evalScripts: true,
239 parameters: params
242 </script>";;
243 DoGet("home/javascript2.rails");
244 AssertReplyEqualTo(expected);
247 [Test]
248 public void OutputSubViewInDiv()
250 string expected = @"<div>
251 Contents for heyhello View
252 </div>";
253 DoGet("home/subview.rails");
254 AssertReplyEqualTo(expected);
257 [Test]
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);
265 [Test]
266 public void DuckOverloadToString()
268 DoGet("home/DuckOverloadToString.rails");
269 AssertReplyEqualTo("20-12-1981");
272 [Test]
273 public void NullPropagation()
275 DoGet("home/NullPropagation.rails");
276 AssertReplyIsBlank();