Support multiple service models for a component. WindsorServiceHostFactory will...
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / BrailBasicFunctionality.cs
blobb725018429e6d42f611a297d6f17b7e4a8b6b9a9
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 ManualResetEvent e = new ManualResetEvent(false);
120 BooViewEngine.ViewRecompiled +=delegate
122 e.Set();
124 using (TextWriter write = File.CreateText(common))
126 write.Write(@new);
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.
131 e.WaitOne();
134 ProcessView_StripRailsExtension("home/hellofromcommon.rails");
135 AssertReplyEqualTo(expected);
137 finally
139 using (TextWriter write = File.CreateText(common))
141 write.Write(old);
144 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
145 // might get the modified version.
146 Thread.Sleep(500);
149 [Test]
150 public void LayoutsChangeOnTheFly()
152 Layout = "defaultlayout";
153 string layout = Path.Combine(ViewSourcePath, @"Views\layouts\defaultlayout.brail");
154 string old;
155 using (TextReader read = File.OpenText(layout))
157 old = read.ReadToEnd();
159 string newLayout = @"start modified
160 ${ChildOutput}
161 end";
162 using (TextWriter write = File.CreateText(layout))
164 write.Write(newLayout);
166 string expected = @"start modified
167 content
168 end";
169 Thread.Sleep(500);
172 ProcessView_StripRailsExtension("defaultlayout/index.rails");
173 AssertReplyEqualTo(expected);
175 finally
177 using (TextWriter write = File.CreateText(layout))
179 write.Write(old);
182 Thread.Sleep(500);
186 [Test]
187 public void PreProcessor()
189 this.PropertyBag.Add("Title", "Ayende");
190 ProcessView_StripRailsExtension("home/preprocessor.rails");
191 string expected =
193 <html>
194 <body>
195 <title>AYENDE</title>
196 <body>
197 <ul>
198 <li>0</li><li>1</li><li>2</li>
199 </ul>
200 </body>
201 </html>
203 AssertReplyEqualTo(expected);
206 [Test]
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);
215 [Test]
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);
225 [Test]
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);
236 [Test]
237 public void Javascript()
239 string expected = @"<script type='text/javascript'>
240 function paginate(index)
242 alert(index);
244 </script>";;
245 ProcessView_StripRailsExtension("home/javascript.rails");
246 AssertReplyEqualTo(expected);
249 [Test]
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, {
258 method: 'get',
259 evalScripts: true,
260 parameters: params
263 </script>"; ;
264 ProcessView_StripRailsExtension("home/javascript2.rails");
265 AssertReplyEqualTo(expected);
268 [Test]
269 public void OutputSubViewInDiv()
271 string expected = @"<div>
272 Contents for heyhello View
273 </div>";
274 ProcessView_StripRailsExtension("home/subview.rails");
275 AssertReplyEqualTo(expected);
278 [Test]
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);
286 [Test]
287 public void DuckOverloadToString()
289 PropertyBag["birthday"] = new DateTime(1981, 12, 20);
290 ProcessView_StripRailsExtension("home/DuckOverloadToString.rails");
291 AssertReplyEqualTo("20-12-1981");
294 [Test]
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
314 get { return text; }
315 set { text = value; }
318 public virtual string Say()
320 return "what?";