More working tests.
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / ComponentsTestCase.cs
blob893d5f5eeba22756bb0345f20bd662b24fbb5111
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.Collections;
18 using Castle.MonoRail.Views.Brail.TestSite.Components;
19 using Castle.MonoRail.Views.Brail.TestSite.Controllers;
20 using Framework;
21 using NUnit.Framework;
23 [TestFixture]
24 public class ComponentsTestCase : BaseViewOnlyTestFixture
26 protected override void BeforEachTest()
28 ViewComponentFactory.Inspect(typeof(BlockViewComponent2).Assembly);
31 [Test]
32 public void BlockComp1()
34 PropertyBag.Add("items", new object[] {1, 2});
35 ProcessView_StripRailsExtension("usingcomponents/index8.rails");
36 AssertReplyEqualTo("\r\ninner content 1\r\n\r\ninner content 2\r\n");
39 [Test]
40 public void CanGetParamsFromTheComponentInTheView()
42 ProcessView_StripRailsExtension("usingcomponents/template.rails");
43 AssertReplyEqualTo("123");
46 [Test]
47 public void CanPassParametersFromComponentToView()
49 ProcessView_StripRailsExtension("usingcomponents/withParams.rails");
50 AssertReplyEqualTo("brail");
53 [Test]
54 public void ComponentWithInvalidSection()
56 try
58 ProcessView_StripRailsExtension("usingcomponent2/ComponentWithInvalidSections.rails");
60 catch (MonoRailException ex)
62 string message = ((ViewComponentException)ex.InnerException).Message;
63 Assert.AreEqual("The section 'invalidsection' is not supported by the ViewComponent 'GridComponent'",
64 message);
68 [Test]
69 public void GridComponent1()
71 FillPropertyBag();
72 ProcessView_StripRailsExtension("usingcomponent2/GridComponent1.rails");
74 AssertReplyEqualTo(
75 @"<table>
76 <th>EMail</th>
77 <th>Phone</th>
78 <tr>
79 <td>hammett</td>
80 <td>111</td>
81 </tr><tr>
82 <td>Peter Griffin</td>
83 <td>222</td>
84 </tr></table>");
87 [Test]
88 public void GridComponent2()
90 PropertyBag.Add("contacts", new ArrayList());
91 ProcessView_StripRailsExtension("usingcomponent2/GridComponent2.rails");
92 AssertReplyEqualTo(
93 @"<table>
94 <th>EMail</th>
95 <th>Phone</th>
96 <tr>
97 <td colspan=2>Nothing here</td>
98 </tr></table>");
101 [Test]
102 public void InlineComponentNotOverridingRender()
104 string expected = "static 1\r\ndefault component view picked up automatically static 2";
105 ProcessView_StripRailsExtension("usingcomponents/index3.rails");
106 AssertReplyEqualTo(expected);
109 [Test]
110 public void InlineComponentUsingRender()
112 string expected = "static 1\r\nThis is a view used by a component static 2";
113 ProcessView_StripRailsExtension("usingcomponents/index2.rails");
114 AssertReplyEqualTo(expected);
117 [Test]
118 public void InlineComponentWithParam1()
120 ProcessView_StripRailsExtension("usingcomponents/index4.rails");
121 AssertReplyEqualTo("Done");
124 [Test]
125 public void SeveralComponentsInvocation()
127 for (int i = 0; i < 10; i++)
129 string expected =
130 "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";
131 ProcessView_StripRailsExtension("usingcomponents/index9.rails");
132 AssertReplyEqualTo(expected);
136 [Test]
137 public void SimpleInlineViewComponent()
139 string expected = "static 1\r\nHello from SimpleInlineViewComponent\r\nstatic 2";
140 ProcessView_StripRailsExtension("usingcomponents/index1.rails");
141 AssertReplyEqualTo(expected);
144 [Test]
145 public void UsingCaptureFor()
147 ProcessView_StripRailsExtension("usingcomponents/captureFor.rails");
148 AssertReplyEqualTo("\r\n1234 Foo, Bar");
151 [Test]
152 public void UsingCaptureForWithLayout()
154 Layout = "layout_with_captureFor";
155 ProcessView_StripRailsExtension("usingcomponents/captureForWithLayout.rails");
156 AssertReplyEqualTo("Numbers: 1234\r\n");
159 private void FillPropertyBag()
161 ArrayList items = new ArrayList();
163 items.Add(new Contact("hammett", "111"));
164 items.Add(new Contact("Peter Griffin", "222"));
166 PropertyBag.Add("contacts", items);
169 public class Contact
171 string email;
172 string phone;
174 public string Email
176 get { return email; }
177 set { email = value; }
180 public string Phone
182 get { return phone; }
183 set { phone = value; }
186 public Contact(string email, string phone)
188 this.email = email;
189 this.phone = phone;