Applying patch from Jonathon Rossi
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / BrailBasicFunctionality.cs
blob7b3bbf739e776c621911fc83995175b777030dae
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.IO;
18 using System.Threading;
19 using Castle.MonoRail.Framework.Tests;
20 using NUnit.Framework;
22 [TestFixture]
23 public class BrailBasicFunctionality : AbstractTestCase
25 [Test]
26 public void AppPath()
28 DoGet("apppath/index.rails");
29 AssertReplyEqualTo("Current apppath is ");
32 [Test, Ignore("Sometimes fail, but the functionality is working.")]
33 public void AppPathChangeOnTheFly()
35 string script = Path.Combine(GetPhysicalDir(), @"Views\AppPath\Index.boo");
36 string newContent = "new content";
37 string old;
38 using(TextReader read = File.OpenText(script))
40 old = read.ReadToEnd();
42 using(TextWriter write = File.CreateText(script))
44 write.Write(newContent);
46 // Wait half a sec so Brail could pick up that a change in the file occured.
47 Thread.Sleep(500);
48 try
50 DoGet("apppath/index.rails");
51 AssertReplyEqualTo(newContent);
53 finally
55 using(TextWriter write = File.CreateText(script))
57 write.Write(old);
62 [Test]
63 public void CommonScripts()
65 DoGet("home/nullables.rails");
66 string expected = "\r\nfoo";
67 AssertReplyEqualTo(expected);
70 [Test]
71 public void Empty()
73 DoGet("home/Empty.rails");
74 string expected = "";
75 AssertReplyEqualTo(expected);
78 [Test, Ignore("Sometimes fail, but the functionality is working.")]
79 public void CommonScriptsChangeOnTheFly()
81 string common = Path.Combine(GetPhysicalDir(), @"Views\CommonScripts\Hello.boo");
82 string old;
83 using(TextReader read = File.OpenText(common))
85 old = read.ReadToEnd();
87 string @new = @"
88 def SayHello(name as string):
89 return 'Hello, \${name}! Modified!'
90 end";
91 using(TextWriter write = File.CreateText(common))
93 write.Write(@new);
95 string expected = "Hello, Ayende! Modified!";
96 // Have to wait for the common scripts recompilation otherwise you get random test failure since the request
97 // sometimes gets there faster you can recompile and it gets the old version.
98 Thread.Sleep(500);
99 try
101 DoGet("home/hellofromcommon.rails");
102 AssertReplyEqualTo(expected);
104 finally
106 using(TextWriter write = File.CreateText(common))
108 write.Write(old);
111 // Have to wait again to make sure that the second recompilation happened, since otherwise a second test
112 // might get the modified version.
113 Thread.Sleep(500);
116 [Test]
117 public void PreProcessor()
119 DoGet("home/preprocessor.rails");
120 string expected =
122 <html>
123 <body>
124 <title>AYENDE</title>
125 <body>
126 <ul>
127 <li>0</li><li>1</li><li>2</li>
128 </ul>
129 </body>
130 </html>
132 AssertReplyEqualTo(expected);