2008-04-16 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System / Test / System.ComponentModel / TypeDescriptorTests.cs
index ce887c7ea82524f97e6ecc1c225807e1db6487fb..68e57aa44581b42408ec58ecee7108d9b8df35fb 100644 (file)
@@ -226,6 +226,35 @@ namespace MonoTests.System.ComponentModel
                        get { return prop; }
                        set { prop = value; }
                }
+
+               public string YetAnotherProperty
+               {
+                       get { return null; }
+               }
+
+               public string Name {
+                       get { return null; }
+               }
+
+               public string Address {
+                       get { return null; }
+               }
+
+               public string Country {
+                       get { return null; }
+               }
+
+               private string HairColor {
+                       get { return null; }
+               }
+
+               protected int Weight {
+                       get { return 5; }
+               }
+
+               internal int Height {
+                       get { return 0; }
+               }
        }
 
        [DescriptionAttribute ("my test derived component")]
@@ -248,6 +277,19 @@ namespace MonoTests.System.ComponentModel
                        get { return prop; }
                        set { prop = value; }
                }
+
+
+               [DescriptionAttribute ("test derived")]
+               public new string AnotherProperty
+               {
+                       get { return base.AnotherProperty; }
+                       set { base.AnotherProperty = value; }
+               }
+
+               public new object YetAnotherProperty
+               {
+                       get { return null; }
+               }
        }
        
 
@@ -720,6 +762,30 @@ namespace MonoTests.System.ComponentModel
                        col = TypeDescriptor.GetProperties (nfscom, filter);
                        Assert.IsNotNull (col.Find ("TestProperty", true), "#F1");
                        Assert.IsNull (col.Find ("AnotherProperty", true), "#F2");
+
+
+                       // GetProperties should return only the last type's implementation of a
+                       // property with a matching name in the base types. E.g in the case where 
+                       // the "new" keyword is used.
+                       //
+                       PropertyDescriptorCollection derivedCol = TypeDescriptor.GetProperties (typeof(MyDerivedComponent));
+                       Assert.IsNotNull (derivedCol["AnotherProperty"].Attributes[typeof (DescriptionAttribute)], "#G1");
+                       int anotherPropsFound = 0;
+                       int yetAnotherPropsFound = 0;
+                       foreach (PropertyDescriptor props in derivedCol) {
+                               if (props.Name == "AnotherProperty")
+                                       anotherPropsFound++;
+                               else if (props.Name == "YetAnotherProperty")
+                                       yetAnotherPropsFound++;
+                       }
+
+                       Assert.AreEqual (1, anotherPropsFound, "#G2");
+
+                       // GetProperties does not return the base type property in the case 
+                       // where both the "new" keyword is used and also the Property type is different 
+                       // (Type.GetProperties does return both properties)
+                       //
+                       Assert.AreEqual (1, yetAnotherPropsFound, "#G3");
                }
 
                [Test]
@@ -740,6 +806,26 @@ namespace MonoTests.System.ComponentModel
                        Assert.IsNull (col.Find ("AnotherProperty", true), "#B2");
                }
 
+               [Test]
+#if ONLY_1_1
+               [NUnit.Framework.Category ("NotDotNet")] // .NET 1.x (or csc 1.x) does not retain the original order
+#endif
+               public void GetProperties_Order ()
+               {
+                       MyComponent com = new MyComponent (new MyContainer ());
+
+                       PropertyDescriptorCollection col = TypeDescriptor.GetProperties (com);
+                       Assert.AreEqual (8, col.Count, "#1");
+                       Assert.AreEqual ("TestProperty", col [0].Name, "#2");
+                       Assert.AreEqual ("AnotherProperty", col [1].Name, "#3");
+                       Assert.AreEqual ("YetAnotherProperty", col [2].Name, "#4");
+                       Assert.AreEqual ("Name", col [3].Name, "#5");
+                       Assert.AreEqual ("Address", col [4].Name, "#6");
+                       Assert.AreEqual ("Country", col [5].Name, "#7");
+                       Assert.AreEqual ("Site", col [6].Name, "#8");
+                       Assert.AreEqual ("Container", col [7].Name, "#9");
+               }
+
                [TypeConverter (typeof (TestConverter))]
                class TestConverterClass {
                }