Minor style changes
[castle.git] / MonoRail / Castle.MonoRail.Framework.Views.NVelocity.Tests / ComponentsTestCase.cs
blob4d732554f2cc2a65e87a1fdd32dd475cdebf34a0
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.Framework.Views.NVelocity.Tests
17 using System;
18 using Castle.MonoRail.Framework.Tests;
19 using NUnit.Framework;
21 [TestFixture]
22 public class ComponentsTestCase : AbstractTestCase
24 [Test]
25 public void CaptureForDirective()
27 DoGet("usingcomponent/capturefordirective.rails");
29 AssertSuccess();
31 AssertReplyContains(@"=navbar= some content =navbar=");
34 [Test]
35 public void CaptureForComponent()
37 DoGet("usingcomponent/capturefor.rails");
39 AssertSuccess();
41 AssertReplyContains(@"=navbar= some content =navbar=");
44 [Test]
45 public void CaptureForComponentAppend()
47 DoGet("usingcomponent/captureforappend.rails");
49 AssertSuccess();
51 AssertReplyContains(@"=2= some content =3= =4=");
54 [Test]
55 public void CaptureForComponentAppendBefore()
57 DoGet("usingcomponent/captureforappendbefore.rails");
59 AssertSuccess();
61 AssertReplyContains(@"=2= some content =4= =3=");
64 [Test]
65 public void InlineComponentUsingRenderText()
67 DoGet("usingcomponent/index1.rails");
69 AssertSuccess();
71 AssertOutput("static 1\r\nHello from SimpleInlineViewComponent static 2", Output);
74 [Test]
75 public void InlineComponentUsingRender()
77 DoGet("usingcomponent/index6.rails");
79 AssertSuccess();
81 AssertOutput("static 1\r\nThis is a view used by a component static 2", Output);
84 [Test]
85 public void InlineComponentUsingTemplatedRender()
87 DoGet("usingcomponent/inlinecomponentusingtemplatedrender.rails");
89 AssertSuccess();
91 AssertOutput("v1 v2 [contains items from property bag] v1 v2 [contains items from property bag]", Output);
94 [Test]
95 public void InlineComponentNotOverridingRender()
97 DoGet("usingcomponent/index3.rails");
99 AssertSuccess();
101 AssertOutput("static 1\r\ndefault component view picked up automatically static 2", Output);
104 [Test]
105 public void InlineComponentWithParam1()
107 DoGet("usingcomponent/index4.rails");
109 AssertSuccess();
111 AssertOutput("Done 1", Output);
114 [Test]
115 public void BlockComp1()
117 DoGet("usingcomponent/index5.rails");
119 AssertSuccess();
121 AssertOutput(" item 0\r\n item 1\r\n item 2\r\n", Output);
124 [Test]
125 public void BlockWithinForEach()
127 DoGet("usingcomponent/index8.rails");
129 AssertSuccess();
131 AssertOutput("inner content 1\r\ninner content 2\r\n", Output);
134 [Test]
135 public void SeveralComponentsInvocation()
137 for(int i = 0; i < 10; i++)
139 DoGet("usingcomponent/index9.rails");
141 AssertSuccess();
143 AssertOutput("static 1\r\nContent 1\r\nstatic 2\r\nContent 2\r\nstatic 3\r\nContent 3\r\nstatic 4\r\nContent 4\r\nstatic 5\r\nContent 5\r\n", Output);
147 [Test]
148 public void ArrayListAsComponentParam()
150 DoGet("usingcomponent/index10.rails");
152 AssertSuccess();
154 AssertOutput("static 1\n1 2 static 2", Output);
157 [Test]
158 public void ComponentWithInvalidSection()
160 DoGet("usingcomponent2/ComponentWithInvalidSections.rails");
162 AssertReplyContains("The section 'invalidsection' is not supported by the ViewComponent 'GridComponent'");
165 [Test]
166 public void GridComponent1()
168 DoGet("usingcomponent2/GridComponent1.rails");
170 AssertReplyContains("<table> <th>EMail</th>\r\n <th>Phone</th>\r\n <tr> <td>hammett</td>\r\n <td>111</td>\r\n </tr><tr> <td>Peter Griffin</td>\r\n <td>222</td>\r\n </tr></table>");
173 [Test]
174 public void GridComponent2()
176 DoGet("usingcomponent2/GridComponent2.rails");
178 AssertReplyContains("<table> <th>EMail</th>\r\n <th>Phone</th>\r\n <tr><td colspan=2>Nothing here</td>\r\n </tr></table>");
181 [Test]
182 public void ComponentAndParams1()
184 DoGet("usingcomponent2/ComponentAndParams1.rails");
186 AssertReplyContains("1 2 True Something hello");
189 [Test]
190 public void ChildContentComponent1()
192 DoGet("usingcomponent2/ChildContentComponent1.rails");
193 AssertReplyContains("View content and Something");
196 [Test]
197 public void ChildContentComponent2()
199 DoGet("usingcomponent2/ChildContentComponent2.rails");
200 AssertReplyContains("View content and 1 2 True Something hello");
203 [Test]
204 public void CanRenderMultipleDynamicComponents()
206 DoGet("usingcomponent/dynamiccomponent.rails");
207 AssertReplyContains("Hello from SimpleInlineViewComponent");
208 AssertReplyContains("This is a view used by a component");
211 [Test]
212 public void AutoParameterBindingMustBeAbleToPerformSimpleConversions()
214 DoGet("usingcomponent2/autoparameterbinding1.rails");
215 AssertReplyContains("'1' 'xpto' 'something.castle?val=1'");
218 [Test]
219 public void AutoParameterBinding_IdIsARequiredParameter()
221 DoGet("usingcomponent2/autoparameterbinding2.rails");
222 AssertReplyContains("The parameter 'Id' is required by the ViewComponent " +
223 "AutoParameterBinding but was not passed or had a null value");
226 private void AssertOutput(String expected, object output)
228 Assert.AreEqual(NormalizeWhitespace(expected), NormalizeWhitespace(output.ToString()));
231 private static string NormalizeWhitespace(String s)
233 return s.Replace("\r\n", "\n");