2 // System.ComponentModel.PropertyDescriptor test cases
5 // Chris Toshok (toshok@ximian.com)
7 // (c) 2006 Novell, Inc. (http://www.novell.com/)
11 using System.Collections;
12 using System.ComponentModel;
13 using System.Globalization;
14 using System.Drawing.Design;
15 using System.ComponentModel.Design;
17 using NUnit.Framework;
19 namespace MonoTests.System.ComponentModel
22 public class PropertyDescriptorTests
24 class MissingConverterType_test
26 public class NestedClass { }
28 [TypeConverter ("missing-type-name")]
29 public NestedClass Prop {
33 [TypeConverter ("missing-type-name")]
38 [TypeConverter ("missing-type-name")]
39 public string StringProp {
44 class ReadOnlyProperty_test
51 class ReadOnlyAttribute_test
60 class ConflictingReadOnly_test
68 class ShouldSerialize_public_test
74 public bool ShouldSerializeProp()
80 class ShouldSerialize_protected_test
86 protected bool ShouldSerializeProp()
92 class ShouldSerialize_private_test
98 private bool ShouldSerializeProp()
104 class ShouldSerializeFalseEffectOnCanReset_test
111 public bool ShouldSerializeProp()
116 public void ResetProp()
121 class NoSerializeOrResetProp_test
128 class CanReset_public_test
133 set { prop = value; }
136 public void ResetProp()
142 class CanReset_protected_test
147 set { prop = value; }
150 protected void ResetProp()
156 class CanReset_private_test
161 set { prop = value; }
164 private void ResetProp()
170 class CanResetNoSetter_test
177 private void ResetProp()
183 class DisplayName_test
186 [DisplayName ("An explicit displayname")]
188 public bool Explicit {
189 get { return false; }
192 public bool Implicit {
193 get { return false; }
198 public void MissingTypeConverter ()
200 PropertyDescriptor p1 = TypeDescriptor.GetProperties (typeof (MissingConverterType_test))["Prop"];
201 PropertyDescriptor p2 = TypeDescriptor.GetProperties (typeof (MissingConverterType_test))["IntProp"];
202 PropertyDescriptor p3 = TypeDescriptor.GetProperties (typeof (MissingConverterType_test))["StringProp"];
204 Assert.AreEqual (typeof (TypeConverter), p1.Converter.GetType (), "1");
205 Assert.AreEqual (typeof (Int32Converter), p2.Converter.GetType (), "2");
206 Assert.AreEqual (typeof (StringConverter), p3.Converter.GetType (), "3");
210 public void ShouldSerializeTest_public ()
212 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (ShouldSerialize_public_test))["Prop"];
213 ShouldSerialize_public_test test = new ShouldSerialize_public_test ();
215 Assert.IsFalse (p.ShouldSerializeValue (test), "1");
219 public void ShouldSerializeTest_protected ()
221 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (ShouldSerialize_protected_test))["Prop"];
222 ShouldSerialize_protected_test test = new ShouldSerialize_protected_test ();
224 Assert.IsFalse (p.ShouldSerializeValue (test), "1");
228 public void ShouldSerializeTest_private ()
230 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (ShouldSerialize_protected_test))["Prop"];
231 ShouldSerialize_protected_test test = new ShouldSerialize_protected_test ();
233 Assert.IsFalse (p.ShouldSerializeValue (test), "1");
237 public void CanResetTest_public ()
239 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (CanReset_public_test))["Prop"];
240 CanReset_public_test test = new CanReset_public_test ();
242 Assert.IsTrue (p.CanResetValue (test), "1");
243 Assert.AreEqual (5, test.Prop, "2");
245 Assert.AreEqual (10, test.Prop, "3");
249 public void CanResetTest_protected ()
251 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (CanReset_protected_test))["Prop"];
252 CanReset_protected_test test = new CanReset_protected_test ();
254 Assert.IsTrue (p.CanResetValue (test), "1");
255 Assert.AreEqual (5, test.Prop, "2");
257 Assert.AreEqual (10, test.Prop, "3");
261 public void CanResetTest_private ()
263 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (CanReset_private_test))["Prop"];
264 CanReset_private_test test = new CanReset_private_test ();
266 Assert.IsTrue (p.CanResetValue (test), "1");
267 Assert.AreEqual (5, test.Prop, "2");
269 Assert.AreEqual (10, test.Prop, "3");
273 public void CanResetTestNoSetterTest ()
275 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (CanResetNoSetter_test))["Prop"];
276 CanResetNoSetter_test test = new CanResetNoSetter_test ();
279 Assert.IsFalse (p.CanResetValue (test), "1");
281 Assert.IsTrue (p.CanResetValue (test), "1");
283 Assert.AreEqual (5, test.Prop, "2");
285 Assert.AreEqual (10, test.Prop, "3");
289 public void NoSerializeOrResetPropTest ()
291 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (NoSerializeOrResetProp_test))["Prop"];
292 NoSerializeOrResetProp_test test = new NoSerializeOrResetProp_test ();
294 Assert.IsFalse (p.CanResetValue (test), "1");
295 Assert.IsFalse (p.ShouldSerializeValue (test), "2");
299 public void ShouldSerializeFalseEffectOnCanResetTest ()
301 PropertyDescriptor p = TypeDescriptor.GetProperties (typeof (ShouldSerializeFalseEffectOnCanReset_test))["Prop"];
302 ShouldSerializeFalseEffectOnCanReset_test test = new ShouldSerializeFalseEffectOnCanReset_test ();
304 Assert.IsFalse (p.ShouldSerializeValue (test), "1");
305 Assert.IsFalse (p.CanResetValue (test), "2");
309 public void ReadOnlyPropertyTest ()
311 PropertyDescriptorCollection col = TypeDescriptor.GetProperties (typeof (ReadOnlyProperty_test));
312 Assert.IsTrue (col["Prop"].IsReadOnly, "1");
316 public void ReadOnlyAttributeTest ()
318 PropertyDescriptorCollection col = TypeDescriptor.GetProperties (typeof (ReadOnlyAttribute_test));
319 Assert.IsTrue (col["Prop"].IsReadOnly, "1");
323 public void ReadOnlyConflictingTest ()
325 PropertyDescriptorCollection col = TypeDescriptor.GetProperties (typeof (ConflictingReadOnly_test));
326 Assert.IsTrue (col["Prop"].IsReadOnly, "1");
330 public void DisplayNameTest ()
332 PropertyDescriptor p1 = TypeDescriptor.GetProperties (typeof (DisplayName_test)) ["Explicit"];
333 PropertyDescriptor p2 = TypeDescriptor.GetProperties (typeof (DisplayName_test)) ["Implicit"];
336 Assert.AreEqual ("An explicit displayname", p1.DisplayName, "#1");
338 Assert.AreEqual ("Explicit", p1.DisplayName, "#1");
340 Assert.AreEqual ("Implicit", p2.DisplayName, "#2");
344 public void GetEditorTest ()
346 PropertyDescriptorCollection col;
347 PropertyDescriptor pd;
350 col = TypeDescriptor.GetProperties (typeof (GetEditor_test));
352 ed = pd.GetEditor (typeof (UITypeEditor)) as UITypeEditor;
354 Assert.IsNotNull (ed, "#01");
355 Assert.AreEqual (ed.GetType ().Name, "UIEditor", "#02");
361 [Editor (typeof (UIEditor), typeof (UITypeEditor))]
362 public string Property {
363 get { return "abc"; }
368 class UIEditor : UITypeEditor