* Makefile: Build the make-map.exe in Mono.Unix.Native; add /nowarn:0618 to
[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]
71                 public void CanConvertFrom ()
72                 {
73                         TypeConverter tc = GetTypeConverter ();
74
75                         Assert.IsFalse (tc.CanConvertFrom (typeof (bool)), "A1");
76                         Assert.IsTrue (tc.CanConvertFrom (typeof (string)), "A2");
77                         Assert.IsTrue (tc.CanConvertFrom (typeof (InstanceDescriptor)), "A3");
78                 }
79
80                 [Test]
81                 public void CanConvertTo ()
82                 {
83                         TypeConverter tc = GetTypeConverter ();
84
85                         Assert.IsFalse (tc.CanConvertTo (typeof (bool)), "A1");
86                         Assert.IsTrue (tc.CanConvertTo (typeof (string)), "A2");
87                         Assert.IsFalse (tc.CanConvertTo (typeof (InstanceDescriptor)), "A3");
88                 }
89
90                 [Test]
91                 public void ConvertFrom ()
92                 {
93                         TypeConverter tc = GetTypeConverter ();
94
95                         Assert.AreEqual ("hi", tc.ConvertTo ("hi", typeof (string)), "A1");
96                         Assert.AreEqual ("", tc.ConvertTo ("", typeof (string)), "A2");
97                 }
98
99                 [Test]
100                 [ExpectedException (typeof (NotSupportedException))]
101                 public void ConvertFromNull ()
102                 {
103                         TypeConverter tc = GetTypeConverter ();
104
105                         tc.ConvertFrom (null);
106                 }
107
108
109                 [Test]
110                 public void ConvertTo ()
111                 {
112                         TypeConverter tc = GetTypeConverter ();
113
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");
119                 }
120         }
121 }
122 #endif