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
;
21 using Castle
.MonoRail
.TestSupport
;
24 public class SmartControllerTestCase
: AbstractTestCase
27 public void StringMethod()
29 DoGet("smart/stringmethod.rails", "name=hammett");
30 String expected
= "incoming hammett";
32 AssertReplyEqualTo(expected
);
34 DoGet("smart/stringmethod.rails", "NAME=hammett");
35 expected
= "incoming hammett";
37 AssertReplyEqualTo(expected
);
43 DoGet("smart/complex.rails", "strarg=hammett", "intarg=1", "strarray=a");
44 String expected
= "incoming hammett 1 a";
46 AssertReplyEqualTo(expected
);
48 DoGet("smart/complex.rails", "strarg=", "intarg=", "strarray=a,b,c");
49 expected
= "incoming 0 a,b,c";
51 AssertReplyEqualTo(expected
);
55 public void SimpleBindArray()
57 DoPost("smart/SimpleBindArray.rails");
58 AssertReplyEqualTo("incoming 0");
60 DoGet("smart/SimpleBindArray.rails");
61 AssertReplyEqualTo("incoming 0");
63 DoGet("smart/SimpleBindArray.rails", "orders[0].Name=hammett", "orders[1].Name=hamilton");
64 AssertReplyEqualTo("incoming 2");
68 public void SimpleBind()
70 DoPost("smart/SimpleBind.rails");
71 String expected
= "incoming 0 0";
72 AssertReplyEqualTo(expected
);
74 DoPost("smart/SimpleBind.rails", "order.name=hammett", "order.itemcount=11", "order.price=20");
75 expected
= "incoming hammett 11 20";
76 AssertReplyEqualTo(expected
);
79 DoPost("smart/SimpleBind.rails", "order.name=hammett", "order.itemcount=11", "order.price=20");
80 expected
= "incoming hammett 11 20";
81 AssertReplyEqualTo(expected
);
83 DoGet("smart/SimpleBind.rails", "order.name=hammett", "order.itemcount=11", "order.price=20");
84 expected
= "incoming hammett 11 20";
85 AssertReplyEqualTo(expected
);
87 DoGet("smart/SimpleBind.rails", "order.name=hammett");
88 expected
= "incoming hammett 0 0";
89 AssertReplyEqualTo(expected
);
93 public void ComplexBind()
95 DoGet( "smart/ComplexBind.rails", "order.name=hammett", "order.itemcount=11", "order.price=20", "person.id=1", "person.contact.email=x", "person.contact.phone=y" );
96 String expected
= "incoming hammett 11 20 1 x y";
98 AssertReplyEqualTo( expected
);
102 public void ComplexBindExcludePrice()
104 DoGet( "smart/ComplexBindExcludePrice.rails", "order.name=hammett", "order.itemcount=11", "order.price=20", "person.id=1", "person.contact.email=x", "person.contact.phone=y" );
105 // This still includes zero in place of price due to
106 // the ToString() method of the domain object and price being of type float
107 String expected
= "incoming hammett 11 0 1 x y";
109 AssertReplyEqualTo( expected
);
113 public void ComplexBindExcludeName()
115 DoGet( "smart/ComplexBindExcludeName.rails", "order.name=hammett", "order.itemcount=11", "order.price=20", "person.id=1", "person.contact.email=x", "person.contact.phone=y" );
116 // This includes an extra space because of the ToString()
117 // method of the domain object and the custom String.Format it contains.
118 String expected
= "incoming 11 20 1 x y";
120 AssertReplyEqualTo( expected
);
124 public void ComplexBindWithPrefix()
126 DoGet("smart/ComplexBindWithPrefix.rails", "order.name=hammett", "order.itemcount=11", "order.price=20", "person.id=1", "person.contact.email=x", "person.contact.phone=y");
127 String expected
= "incoming hammett 11 20 1 x y";
129 AssertReplyEqualTo(expected
);
133 public void FillingBehavior1()
136 System
.Threading
.Thread
.CurrentThread
.CurrentCulture
= System
.Globalization
.CultureInfo
.InvariantCulture
;
137 DoGet("smart/FillingBehavior.rails", "abc.name=someone", "abc.date1day=11", "abc.date1month=10", "abc.date1year=2005");
138 String expected
= "incoming someone " + new DateTime( 2005, 10, 11 ).ToShortDateString() + " " +
139 DateTime
.Now
.AddDays(1).ToShortDateString();
141 AssertReplyEqualTo(expected
);
145 public void FillingBehavior2()
147 System
.Threading
.Thread
.CurrentThread
.CurrentCulture
= System
.Globalization
.CultureInfo
.InvariantCulture
;
148 DoGet("smart/FillingBehavior.rails");
149 String expected
= "incoming hammett " +
150 DateTime
.Now
.ToShortDateString() + " " + DateTime
.Now
.AddDays(1).ToShortDateString();
152 AssertReplyEqualTo(expected
);
156 public void NullableConversion1()
158 DoGet("smart/NullableConversion.rails", "amount=");
159 String expected
= "incoming False ";
161 AssertReplyEqualTo(expected
);
165 public void NullableConversion2()
167 DoGet("smart/NullableConversion.rails", "amount=0");
168 String expected
= "incoming True 0";
170 AssertReplyEqualTo(expected
);
174 public void NullableConversion3()
176 DoGet("smart/NullableConversion.rails", "amount=11.2");
177 String expected
= "incoming True 11.2";
179 AssertReplyEqualTo(expected
);
183 public void NullableAndDataBind()
185 DoGet("smart/NullableConversion2.rails", "mov.name=hammett", "mov.amount=11");
186 String expected
= "incoming hammett 11";
188 AssertReplyEqualTo(expected
);
192 public void NullableAndDataBind2()
194 DoGet("smart/NullableConversion2.rails", "mov.name=hammett");
195 String expected
= "incoming hammett ";
197 AssertReplyEqualTo(expected
);
201 public void ArrayBinding1()
203 DoGet("smart/ArrayBinding.rails", "user.name=hammett", "user.roles=1", "user.roles=2", "user.permissions=10", "user.permissions=11");
204 String expected
= "User hammett 2 2 1 2 10 11";
206 AssertReplyEqualTo(expected
);
210 public void BugReportedOnForum1()
212 DoGet("smart/CalculateUtilizationByDay.rails", "tp1.Hour=1", "tp1.Minute=2", "tp1.Second=3", "tp2.Hour=10", "tp2.Minute=20", "tp2.Second=30");
213 String expected
= " 1:2:3 10:20:30 ";
215 AssertReplyEqualTo(expected
);