1 // Copyright 2004-2008 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
.Views
.Brail
.Tests
17 using System
.Collections
;
18 using Castle
.MonoRail
.Views
.Brail
.TestSite
.Components
;
19 using Castle
.MonoRail
.Views
.Brail
.TestSite
.Controllers
;
21 using NUnit
.Framework
;
24 public class ComponentsTestCase
: BaseViewOnlyTestFixture
26 protected override void BeforEachTest()
28 ViewComponentFactory
.Inspect(typeof(BlockViewComponent2
).Assembly
);
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");
40 public void CanGetParamsFromTheComponentInTheView()
42 ProcessView_StripRailsExtension("usingcomponents/template.rails");
43 AssertReplyEqualTo("123");
47 public void CanPassParametersFromComponentToView()
49 ProcessView_StripRailsExtension("usingcomponents/withParams.rails");
50 AssertReplyEqualTo("brail");
54 public void ComponentWithInvalidSection()
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'",
69 public void GridComponent1()
72 ProcessView_StripRailsExtension("usingcomponent2/GridComponent1.rails");
82 <td>Peter Griffin</td>
88 public void GridComponent2()
90 PropertyBag
.Add("contacts", new ArrayList());
91 ProcessView_StripRailsExtension("usingcomponent2/GridComponent2.rails");
97 <td colspan=2>Nothing here</td>
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
);
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
);
118 public void InlineComponentWithParam1()
120 ProcessView_StripRailsExtension("usingcomponents/index4.rails");
121 AssertReplyEqualTo("Done");
125 public void SeveralComponentsInvocation()
127 for (int i
= 0; i
< 10; i
++)
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
);
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
);
145 public void UsingCaptureFor()
147 ProcessView_StripRailsExtension("usingcomponents/captureFor.rails");
148 AssertReplyEqualTo("\r\n1234 Foo, Bar");
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
);
176 get { return email; }
177 set { email = value; }
182 get { return phone; }
183 set { phone = value; }
186 public Contact(string email
, string phone
)