2 // System.ComponentModel.TypeConverter test cases
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // (c) 2005 Novell, Inc. (http://www.ximian.com)
11 using System.ComponentModel;
12 using System.ComponentModel.Design.Serialization;
14 using NUnit.Framework;
16 namespace MonoTests.System.ComponentModel
19 public class TypeConverterTests
22 public void DefaultImplementation ()
24 BConverter converter = new BConverter ();
27 Assert.IsNull (converter.GetProperties (c), "#1");
28 Assert.IsNull (converter.GetProperties (null, c), "#2");
29 Assert.IsNull (converter.GetProperties (null, c, null), "#3");
31 Assert.IsNull (converter.GetProperties (null), "#4");
32 Assert.IsNull (converter.GetProperties (null, null), "#5");
33 Assert.IsNull (converter.GetProperties (null, null, null), "#6");
34 Assert.IsFalse (converter.GetCreateInstanceSupported (), "#7");
35 Assert.IsFalse (converter.GetCreateInstanceSupported (null), "#8");
36 Assert.IsFalse (converter.GetPropertiesSupported (), "#9");
37 Assert.IsFalse (converter.GetPropertiesSupported (null), "#10");
39 Assert.IsTrue (converter.CanConvertFrom (typeof (InstanceDescriptor)), "#11");
40 Assert.IsTrue (converter.CanConvertFrom (null, typeof (InstanceDescriptor)), "#12");
41 Assert.IsTrue (converter.CanConvertTo (typeof (string)), "#13");
42 Assert.IsTrue (converter.CanConvertTo (null, typeof (string)), "#14");
46 public void GetProperties ()
48 PropertyDescriptorCollection properties = null;
50 TypeConverter converter = TypeDescriptor.GetConverter (c);
52 Assert.AreEqual (typeof (AConverter).FullName, converter.GetType ().FullName, "#1");
54 properties = converter.GetProperties (c);
55 Assert.AreEqual (1, properties.Count, "#2");
56 Assert.AreEqual ("A", properties[0].Name, "#3");
58 // ensure collection is read-only
62 } catch (NotSupportedException) {
63 // read-only collection cannot be modified
66 properties = converter.GetProperties (null, c);
67 Assert.AreEqual (1, properties.Count, "#5");
68 Assert.AreEqual ("A", properties[0].Name, "#6");
71 // ensure collection is read-only
75 } catch (NotSupportedException) {
76 // read-only collection cannot be modified
79 properties = converter.GetProperties (null, c, null);
80 Assert.AreEqual (2, properties.Count, "#8");
82 // ensure collection is read-only
86 } catch (NotSupportedException) {
87 // read-only collection cannot be modified
90 properties = converter.GetProperties (null);
91 Assert.IsNull (properties, "#10");
93 properties = converter.GetProperties (null, null);
94 Assert.IsNull (properties, "#11");
96 properties = converter.GetProperties (null, null, null);
97 Assert.IsNull (properties, "#12");
101 [TypeConverter (typeof (AConverter))]
115 public class AConverter : TypeConverter
117 public override PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value, Attribute[] attributes)
120 return TypeDescriptor.GetProperties (value, attributes);
122 return base.GetProperties (context, value, attributes);
125 public override bool GetPropertiesSupported (ITypeDescriptorContext context)
131 public class BConverter : TypeConverter