2 // Tests for System.Web.UI.MinimizableAttributeTypeConvert.cs
5 // Chris Toshok (toshok@ximian.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.
32 using System.ComponentModel;
33 using System.ComponentModel.Design.Serialization;
36 using System.Web.UI.HtmlControls;
37 using System.Reflection;
38 using NUnit.Framework;
41 namespace MonoTests.System.Web.UI {
44 public class MinimizableAttributeTypeConverterTest {
45 private TypeConverter GetTypeConverter ()
47 Type t = typeof (HtmlTableCell);
49 PropertyInfo pi = null;
52 props = t.GetProperties();
54 foreach (PropertyInfo p in props) {
55 if (p.Name == "NoWrap") {
61 object[] attrs = pi.GetCustomAttributes (typeof (TypeConverterAttribute), false);
62 TypeConverterAttribute tca = (TypeConverterAttribute)attrs[0];
64 Type tct = Type.GetType (tca.ConverterTypeName);
65 tc = (TypeConverter)Activator.CreateInstance (tct);
71 public void CanConvertFrom ()
73 TypeConverter tc = GetTypeConverter ();
75 Assert.IsFalse (tc.CanConvertFrom (typeof (bool)), "A1");
76 Assert.IsTrue (tc.CanConvertFrom (typeof (string)), "A2");
77 Assert.IsTrue (tc.CanConvertFrom (typeof (InstanceDescriptor)), "A3");
81 public void CanConvertTo ()
83 TypeConverter tc = GetTypeConverter ();
85 Assert.IsFalse (tc.CanConvertTo (typeof (bool)), "A1");
86 Assert.IsTrue (tc.CanConvertTo (typeof (string)), "A2");
87 Assert.IsFalse (tc.CanConvertTo (typeof (InstanceDescriptor)), "A3");
91 public void ConvertFrom ()
93 TypeConverter tc = GetTypeConverter ();
95 Assert.AreEqual ("hi", tc.ConvertTo ("hi", typeof (string)), "A1");
96 Assert.AreEqual ("", tc.ConvertTo ("", typeof (string)), "A2");
100 [ExpectedException (typeof (NotSupportedException))]
101 public void ConvertFromNull ()
103 TypeConverter tc = GetTypeConverter ();
105 tc.ConvertFrom (null);
110 public void ConvertTo ()
112 TypeConverter tc = GetTypeConverter ();
114 Assert.AreEqual ("hi", tc.ConvertTo ("hi", typeof (string)), "A1");
115 Assert.AreEqual ("", tc.ConvertTo ("", typeof (string)), "A2");
116 Assert.AreEqual ("", tc.ConvertTo (null, typeof (string)), "A3");
117 Assert.AreEqual ("False", tc.ConvertTo (false, typeof (string)), "A4");
118 Assert.AreEqual ("True", tc.ConvertTo (true, typeof (string)), "A5");