2 // Tests for System.Web.UI.WebControls.ListBoxTest.cs
5 // Vladimir Krasnov (vladimirk@mainsoft.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using NUnit.Framework;
37 using System.Collections.Specialized;
38 using System.Globalization;
41 using System.Web.UI.WebControls;
43 using MonoTests.stand_alone.WebHarness;
44 using MonoTests.SystemWeb.Framework;
45 using System.Web.Compilation;
47 namespace MonoTests.System.Web.Compilation
49 public class SettingTestingType
51 private string strProp;
53 private DateTime dateTimeProp;
54 private Type typeProp;
56 public string StrProp {
57 get { return strProp; }
58 set { strProp = value; }
62 get { return intProp; }
63 set { intProp = value; }
66 public DateTime DateTimeProp {
67 get { return dateTimeProp; }
68 set { dateTimeProp = value; }
71 public Type TypeProp {
72 get { return typeProp; }
73 set { typeProp = value; }
78 public class AppSettingsExpressionBuilderTest
80 [Test] // GetAppSetting (String)
81 [Category ("NunitWeb")]
82 public void GetAppSetting1 ()
84 PageDelegates pd = new PageDelegates ();
85 pd.Load = GetAppSetting1_Load;
86 WebTest test = new WebTest (new PageInvoker (pd));
90 [Test] // GetAppSetting (String)
91 public void GetAppSetting1_Key_DoesNotExist ()
94 AppSettingsExpressionBuilder.GetAppSetting ("DoesNotExist");
96 } catch (InvalidOperationException ex) {
97 // The application setting 'DoesNotExist' was
98 // not found in the applications configuration
99 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
100 Assert.IsNull (ex.InnerException, "#3");
101 Assert.IsNotNull (ex.Message, "#4");
102 Assert.IsTrue (ex.Message.IndexOf ("'DoesNotExist'") != -1, "#5");
106 [Test] // GetAppSetting (String)
107 public void GetAppSetting1_Key_Null ()
110 AppSettingsExpressionBuilder.GetAppSetting ((string) null);
112 } catch (InvalidOperationException ex) {
113 // The application setting '' was not found in
114 // the applications configuration
115 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
116 Assert.IsNull (ex.InnerException, "#3");
117 Assert.IsNotNull (ex.Message, "#4");
118 Assert.IsTrue (ex.Message.IndexOf ("''") != -1, "#5");
122 [Test] // GetAppSetting (String, Type, String)
123 [Category ("NunitWeb")]
124 public void GetAppSetting2 ()
126 PageDelegates pd = new PageDelegates ();
127 pd.Load = GetAppSetting2_Load;
128 WebTest test = new WebTest (new PageInvoker (pd));
132 [Test] // GetAppSetting (String, Type, String)
133 public void GetAppSetting2_Key_Null ()
136 AppSettingsExpressionBuilder.GetAppSetting (
138 typeof (SettingTestingType),
141 } catch (InvalidOperationException ex) {
142 // The application setting '' was not found in
143 // the applications configuration
144 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
145 Assert.IsNull (ex.InnerException, "#3");
146 Assert.IsNotNull (ex.Message, "#4");
147 Assert.IsTrue (ex.Message.IndexOf ("''") != -1, "#5");
152 public void SupportsEvaluate ()
154 AppSettingsExpressionBuilder aseb = new AppSettingsExpressionBuilder ();
155 Assert.IsTrue (aseb.SupportsEvaluate);
158 public static void GetAppSetting1_Load (Page p)
160 object o = AppSettingsExpressionBuilder.GetAppSetting ("strvalue");
161 Assert.AreEqual (typeof (string), o.GetType (), "#A1");
162 Assert.AreEqual ("str", o, "#A2");
164 o = AppSettingsExpressionBuilder.GetAppSetting ("intvalue");
165 Assert.AreEqual (typeof (string), o.GetType (), "#B1");
166 Assert.AreEqual ("123", o, "#B2");
169 public static void GetAppSetting2_Load (Page p)
171 object o = AppSettingsExpressionBuilder.GetAppSetting ("strvalue", typeof (SettingTestingType), "StrProp");
172 Assert.AreEqual (typeof (string), o.GetType (), "#A1");
173 Assert.AreEqual ("str", o, "#A2");
175 // property does not exist
176 o = AppSettingsExpressionBuilder.GetAppSetting ("strvalue", typeof (SettingTestingType), "NotExistsProp");
177 Assert.AreEqual (typeof (string), o.GetType (), "#B1");
178 Assert.AreEqual ("str", o, "#B2");
180 o = AppSettingsExpressionBuilder.GetAppSetting ("intvalue", typeof (SettingTestingType), "IntProp");
181 Assert.AreEqual (typeof (int), o.GetType (), "#C1");
182 Assert.AreEqual (123, o, "#C2");
185 o = AppSettingsExpressionBuilder.GetAppSetting ("intvalue", typeof (SettingTestingType), "StrProp");
186 Assert.AreEqual (typeof (string), o.GetType (), "#D1");
187 Assert.AreEqual ("123", o, "#D2");
189 // property does not exist
190 o = AppSettingsExpressionBuilder.GetAppSetting ("intvalue", typeof (SettingTestingType), "NotExistsProp");
191 Assert.AreEqual (typeof (string), o.GetType (), "#E1");
192 Assert.AreEqual ("123", o, "#E2");
195 o = AppSettingsExpressionBuilder.GetAppSetting ("intvalue", (Type) null, "NotExistsProp");
196 Assert.AreEqual (typeof (string), o.GetType (), "#F1");
197 Assert.AreEqual ("123", o, "#F2");
201 AppSettingsExpressionBuilder.GetAppSetting ("intvalue",
202 typeof (SettingTestingType), "DateTimeProp");
204 } catch (FormatException ex) {
205 // String was not recognized as a valid DateTime
206 Assert.AreEqual (typeof (FormatException), ex.GetType (), "#G2");
207 Assert.IsNotNull (ex.Message, "#G3");
210 // conversion not supported
212 AppSettingsExpressionBuilder.GetAppSetting ("intvalue",
213 typeof (SettingTestingType), "TypeProp");
215 } catch (InvalidOperationException ex) {
216 // Could not convert the AppSetting '123' to the
217 // type 'Type' on property 'TypeProp'
218 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#H2");
219 Assert.IsNull (ex.InnerException, "#H3");
220 Assert.IsNotNull (ex.Message, "#H4");
221 Assert.IsTrue (ex.Message.IndexOf ("'123'") != -1, "#H5");
222 Assert.IsTrue (ex.Message.IndexOf ("'Type'") != -1, "#H6");
223 Assert.IsTrue (ex.Message.IndexOf ("'TypeProp'") != -1, "#H7");
228 AppSettingsExpressionBuilder.GetAppSetting ("intvalue",
229 typeof (SettingTestingType), (string) null);
231 } catch (ArgumentNullException ex) {
232 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#I2");
233 Assert.IsNull (ex.InnerException, "#I3");
234 Assert.IsNotNull (ex.Message, "#I4");
235 //Assert.AreEqual ("key", ex.ParamName, "#I5");