Update Castle.MicroKernel-vs2005.csproj with missing files.
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / BrailBasicFunctionality.cs
blobf010d7c08a541bac9843f4d1e2da177ca73c0262
1 // Copyright 2004-2008 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.Collections;
19 using System.IO;
20 using System.Net;
21 using System.Threading;
22 using DynamicProxy;
23 using NUnit.Framework;
25 [TestFixture]
26 public class BrailBasicFunctionality : BaseViewOnlyTestFixture
28 [Test]
29 public void AppPath()
31 ProcessView_StripRailsExtension("apppath/index.rails");
32 AssertReplyEqualTo("Current apppath is /TestBrail");
35 [Test]
36 public void CanUseUrlHelperWithoutPrefix()
38 PropertyBag["url"] = "blah";
40 ProcessView_StripRailsExtension("home/CanUseUrlHelperWithoutPrefix.rails");
41 AssertReplyEqualTo("Castle.MonoRail.Framework.Helpers.UrlHelper");
44 [Test]
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
52 foo
53 what?
54 there";
55 AssertReplyEqualTo(expected);
58 [Test]
59 public void AppPathChangeOnTheFly()
61 string script = Path.Combine(ViewSourcePath, @"Views\AppPath\Index.brail");
62 string newContent = "new content";
63 string old;
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);
72 write.Flush();
74 Thread.Sleep(1000);
75 try
77 ProcessView_StripRailsExtension("apppath/index.rails");
78 AssertReplyEqualTo(newContent);
80 finally
82 using (TextWriter write = File.CreateText(script))
84 write.Write(old);
89 [Test]
90 public void CommonScripts()
92 PropertyBag["doesExists"] = "foo";
93 ProcessView_StripRailsExtension("home/nullables.rails");
94 string expected = "\r\nfoo";
95 AssertReplyEqualTo(expected);
98 [Test]
99 public void Empty()
101 ProcessView_StripRailsExtension("home/Empty.rails");
102 string expected = "";
103 AssertReplyEqualTo(expected);
106 [Test]
107 public void CommonScriptsChangeOnTheFly()
109 string common = Path.Combine(ViewSourcePath, @"Views\CommonScripts\Hello.brail");
110 string old;
111 using (TextReader read = File.OpenText(common))
113 old = read.ReadToEnd();
115 string @new = @"
116 def SayHello(name as string):
117 return 'Hello, '+name+'! Modified!'
118 end";
119 using (TextWriter write = File.CreateText(common))
121 write.Write(@new);
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.
126 Thread.Sleep(500);
129 ProcessView_StripRailsExtension("home/hellofromcommon.rails");
130 AssertReplyEqualTo(expected);
132 finally
134 using (TextWriter write = File.CreateText(common))
136 write.Write(old);
139 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
140 // might get the modified version.
141 Thread.Sleep(500);
144 [Test]
145 public void LayoutsChangeOnTheFly()
147 Layout = "defaultlayout";
148 string layout = Path.Combine(ViewSourcePath, @"Views\layouts\defaultlayout.brail");
149 string old;
150 using (TextReader read = File.OpenText(layout))
152 old = read.ReadToEnd();
154 string newLayout = @"start modified
155 ${ChildOutput}
156 end";
157 using (TextWriter write = File.CreateText(layout))
159 write.Write(newLayout);
161 string expected = @"start modified
162 content
163 end";
164 Thread.Sleep(500);
167 ProcessView_StripRailsExtension("defaultlayout/index.rails");
168 AssertReplyEqualTo(expected);
170 finally
172 using (TextWriter write = File.CreateText(layout))
174 write.Write(old);
177 Thread.Sleep(500);
181 [Test]
182 public void PreProcessor()
184 this.PropertyBag.Add("Title", "Ayende");
185 ProcessView_StripRailsExtension("home/preprocessor.rails");
186 string expected =
188 <html>
189 <body>
190 <title>AYENDE</title>
191 <body>
192 <ul>
193 <li>0</li><li>1</li><li>2</li>
194 </ul>
195 </body>
196 </html>
198 AssertReplyEqualTo(expected);
201 [Test]
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);
210 [Test]
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);
220 [Test]
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);
231 [Test]
232 public void Javascript()
234 string expected = @"<script type='text/javascript'>
235 function paginate(index)
237 alert(index);
239 </script>";;
240 ProcessView_StripRailsExtension("home/javascript.rails");
241 AssertReplyEqualTo(expected);
244 [Test]
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, {
253 method: 'get',
254 evalScripts: true,
255 parameters: params
258 </script>"; ;
259 ProcessView_StripRailsExtension("home/javascript2.rails");
260 AssertReplyEqualTo(expected);
263 [Test]
264 public void OutputSubViewInDiv()
266 string expected = @"<div>
267 Contents for heyhello View
268 </div>";
269 ProcessView_StripRailsExtension("home/subview.rails");
270 AssertReplyEqualTo(expected);
273 [Test]
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);
281 [Test]
282 public void DuckOverloadToString()
284 PropertyBag["birthday"] = new DateTime(1981, 12, 20);
285 ProcessView_StripRailsExtension("home/DuckOverloadToString.rails");
286 AssertReplyEqualTo("20-12-1981");
289 [Test]
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
309 get { return text; }
310 set { text = value; }
313 public virtual string Say()
315 return "what?";