New test.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / MinimizableAttributeTypeConverterTest.cs
1 //
2 // Tests for System.Web.UI.MinimizableAttributeTypeConvert.cs 
3 //
4 // Author:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.ComponentModel;
33 using System.ComponentModel.Design.Serialization;
34 using System.IO;
35 using System.Web.UI;
36 using System.Web.UI.HtmlControls;
37 using System.Reflection;
38 using NUnit.Framework;
39
40 #if NET_2_0
41 namespace MonoTests.System.Web.UI {
42
43         [TestFixture]
44         public class MinimizableAttributeTypeConverterTest {
45                 private TypeConverter GetTypeConverter ()
46                 {
47                         Type t = typeof (HtmlTableCell);
48                         PropertyInfo[] props;
49                         PropertyInfo pi = null;
50                         TypeConverter tc;
51
52                         props = t.GetProperties();
53
54                         foreach (PropertyInfo p in props) {
55                                 if (p.Name == "NoWrap") {
56                                         pi = p;
57                                         break;
58                                 }
59                         }
60
61                         object[] attrs = pi.GetCustomAttributes (typeof (TypeConverterAttribute), false);
62                         TypeConverterAttribute tca = (TypeConverterAttribute)attrs[0];
63
64                         Type tct = Type.GetType (tca.ConverterTypeName);
65                         tc = (TypeConverter)Activator.CreateInstance (tct);
66
67                         return tc;
68                 }
69
70                 [Test]\r
71 #if TARGET_JVM\r
72                 [NUnit.Framework.Category ("NotWorking")]\r
73 #endif
74                 public void CanConvertFrom ()
75                 {
76                         TypeConverter tc = GetTypeConverter ();
77
78                         Assert.IsFalse (tc.CanConvertFrom (typeof (bool)), "A1");
79                         Assert.IsTrue (tc.CanConvertFrom (typeof (string)), "A2");
80                         Assert.IsTrue (tc.CanConvertFrom (typeof (InstanceDescriptor)), "A3");
81                 }
82
83                 [Test]
84                 public void CanConvertTo ()
85                 {
86                         TypeConverter tc = GetTypeConverter ();
87
88                         Assert.IsFalse (tc.CanConvertTo (typeof (bool)), "A1");
89                         Assert.IsTrue (tc.CanConvertTo (typeof (string)), "A2");
90                         Assert.IsFalse (tc.CanConvertTo (typeof (InstanceDescriptor)), "A3");
91                 }
92
93                 [Test]
94                 public void ConvertFrom ()
95                 {
96                         TypeConverter tc = GetTypeConverter ();
97
98                         Assert.AreEqual ("hi", tc.ConvertTo ("hi", typeof (string)), "A1");
99                         Assert.AreEqual ("", tc.ConvertTo ("", typeof (string)), "A2");
100                 }
101
102                 [Test]
103                 [ExpectedException (typeof (NotSupportedException))]
104                 public void ConvertFromNull ()
105                 {
106                         TypeConverter tc = GetTypeConverter ();
107
108                         tc.ConvertFrom (null);
109                 }
110
111
112                 [Test]
113                 public void ConvertTo ()
114                 {
115                         TypeConverter tc = GetTypeConverter ();
116
117                         Assert.AreEqual ("hi", tc.ConvertTo ("hi", typeof (string)), "A1");
118                         Assert.AreEqual ("", tc.ConvertTo ("", typeof (string)), "A2");
119                         Assert.AreEqual ("", tc.ConvertTo (null, typeof (string)), "A3");
120                         Assert.AreEqual ("False", tc.ConvertTo (false, typeof (string)), "A4");
121                         Assert.AreEqual ("True", tc.ConvertTo (true, typeof (string)), "A5");
122                 }
123         }
124 }
125 #endif