1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using Castle
.MonoRail
.Framework
.Tests
;
19 using NUnit
.Framework
;
22 public class ComponentsTestCase
: AbstractTestCase
25 public void CaptureForDirective()
27 DoGet("usingcomponent/capturefordirective.rails");
31 AssertReplyContains(@"=navbar= some content =navbar=");
35 public void CaptureForComponent()
37 DoGet("usingcomponent/capturefor.rails");
41 AssertReplyContains(@"=navbar= some content =navbar=");
45 public void CaptureForComponentAppend()
47 DoGet("usingcomponent/captureforappend.rails");
51 AssertReplyContains(@"=2= some content =3= =4=");
55 public void CaptureForComponentAppendBefore()
57 DoGet("usingcomponent/captureforappendbefore.rails");
61 AssertReplyContains(@"=2= some content =4= =3=");
65 public void InlineComponentUsingRenderText()
67 DoGet("usingcomponent/index1.rails");
71 AssertOutput("static 1\r\nHello from SimpleInlineViewComponent static 2", Output
);
75 public void InlineComponentUsingRender()
77 DoGet("usingcomponent/index6.rails");
81 AssertOutput("static 1\r\nThis is a view used by a component static 2", Output
);
85 public void InlineComponentUsingTemplatedRender()
87 DoGet("usingcomponent/inlinecomponentusingtemplatedrender.rails");
91 AssertOutput("v1 v2 [contains items from property bag] v1 v2 [contains items from property bag]", Output
);
95 public void InlineComponentNotOverridingRender()
97 DoGet("usingcomponent/index3.rails");
101 AssertOutput("static 1\r\ndefault component view picked up automatically static 2", Output
);
105 public void InlineComponentWithParam1()
107 DoGet("usingcomponent/index4.rails");
111 AssertOutput("Done 1", Output
);
115 public void BlockComp1()
117 DoGet("usingcomponent/index5.rails");
121 AssertOutput(" item 0\r\n item 1\r\n item 2\r\n", Output
);
125 public void BlockWithinForEach()
127 DoGet("usingcomponent/index8.rails");
131 AssertOutput("inner content 1\r\ninner content 2\r\n", Output
);
135 public void SeveralComponentsInvocation()
137 for(int i
= 0; i
< 10; i
++)
139 DoGet("usingcomponent/index9.rails");
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
);
148 public void ArrayListAsComponentParam()
150 DoGet("usingcomponent/index10.rails");
154 AssertOutput("static 1\n1 2 static 2", Output
);
158 public void ComponentWithInvalidSection()
160 DoGet("usingcomponent2/ComponentWithInvalidSections.rails");
162 AssertReplyContains("The section 'invalidsection' is not supported by the ViewComponent 'GridComponent'");
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>");
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>");
182 public void ComponentAndParams1()
184 DoGet("usingcomponent2/ComponentAndParams1.rails");
186 AssertReplyContains("1 2 True Something hello");
190 public void ChildContentComponent1()
192 DoGet("usingcomponent2/ChildContentComponent1.rails");
193 AssertReplyContains("View content and Something");
197 public void ChildContentComponent2()
199 DoGet("usingcomponent2/ChildContentComponent2.rails");
200 AssertReplyContains("View content and 1 2 True Something hello");
204 public void CanRenderMultipleDynamicComponents()
206 DoGet("usingcomponent/dynamiccomponent.rails");
207 AssertReplyContains("Hello from SimpleInlineViewComponent");
208 AssertReplyContains("This is a view used by a component");
212 public void AutoParameterBindingMustBeAbleToPerformSimpleConversions()
214 DoGet("usingcomponent2/autoparameterbinding1.rails");
215 AssertReplyContains("'1' 'xpto' 'something.castle?val=1'");
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");