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");
47 [Ignore ("TD BUG ID: 7229")]
49 public void GetProperties ()
51 PropertyDescriptorCollection properties = null;
53 TypeConverter converter = TypeDescriptor.GetConverter (c);
55 Assert.AreEqual (typeof (AConverter).FullName, converter.GetType ().FullName, "#1");
57 properties = converter.GetProperties (c);
58 Assert.AreEqual (1, properties.Count, "#2");
59 Assert.AreEqual ("A", properties[0].Name, "#3");
61 // ensure collection is read-only
65 } catch (NotSupportedException) {
66 // read-only collection cannot be modified
69 properties = converter.GetProperties (null, c);
70 Assert.AreEqual (1, properties.Count, "#5");
71 Assert.AreEqual ("A", properties[0].Name, "#6");
74 // ensure collection is read-only
78 } catch (NotSupportedException) {
79 // read-only collection cannot be modified
82 properties = converter.GetProperties (null, c, null);
83 Assert.AreEqual (2, properties.Count, "#8");
85 // ensure collection is read-only
89 } catch (NotSupportedException) {
90 // read-only collection cannot be modified
93 properties = converter.GetProperties (null);
94 Assert.IsNull (properties, "#10");
96 properties = converter.GetProperties (null, null);
97 Assert.IsNull (properties, "#11");
99 properties = converter.GetProperties (null, null, null);
100 Assert.IsNull (properties, "#12");
104 [TypeConverter (typeof (AConverter))]
118 public class AConverter : TypeConverter
120 public override PropertyDescriptorCollection GetProperties (ITypeDescriptorContext context, object value, Attribute[] attributes)
123 return TypeDescriptor.GetProperties (value, attributes);
125 return base.GetProperties (context, value, attributes);
128 public override bool GetPropertiesSupported (ITypeDescriptorContext context)
134 public class BConverter : TypeConverter