Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / corlib / Test / System.Reflection / PropertyInfoTest.cs
index c918caf9af5b5017235b1612e654bd43a22c102a..f461e8be636edf1285b2cf22e5f17ac6b6fb5e60 100644 (file)
@@ -31,7 +31,9 @@ using System;
 using System.Reflection;
 using System.Runtime.InteropServices;
 using System.Threading;
+#if !MONOTOUCH
 using System.Reflection.Emit;
+#endif
 using System.IO;
 
 using NUnit.Framework;
@@ -354,7 +356,7 @@ namespace MonoTests.System.Reflection
                                get { return 99; }
                        }
                }
-
+#if !MONOTOUCH
                [Test]
                public void ConstantValue () {
                        /*This test looks scary because we can't generate a default value with C# */
@@ -399,8 +401,8 @@ namespace MonoTests.System.Reflection
                        } catch (InvalidOperationException) {
                        }
                }
+#endif
 
-#if NET_2_0
                public class A<T>
                {
                        public string Property {
@@ -436,8 +438,13 @@ namespace MonoTests.System.Reflection
                        PropertyInfo property = type.GetProperty ("Property");
                        Assert.AreEqual (typeof (string).FullName, property.GetValue (instance, null));
                }
-#endif
 
+               [Test]
+               public void ToStringTest ()
+               {
+                       var pa = typeof (TestC).GetProperty ("Item");
+                       Assert.AreEqual ("Int32 Item [Double[]]", pa.ToString ());
+               }
 
                static bool HasAttribute (object [] attrs, Type attributeType)
                {
@@ -480,5 +487,64 @@ namespace MonoTests.System.Reflection
                        }
 #endif
                }
+
+               [Test] // bug #633671
+               public void DeclaringTypeOfPropertyFromInheritedTypePointsToBase ()
+               {
+                       var inherit1 = typeof(InheritsFromClassWithNullableDateTime);
+                       var siblingProperty = inherit1.GetProperty("Property1");
+
+                       Assert.AreEqual (typeof (ClassWithNullableDateTime), siblingProperty.DeclaringType, "#1");
+                       Assert.AreEqual (typeof (InheritsFromClassWithNullableDateTime), siblingProperty.ReflectedType, "#2");
+
+                       //The check is done twice since the bug is related to getting those 2 properties multiple times.
+                       Assert.AreEqual (typeof (ClassWithNullableDateTime), siblingProperty.DeclaringType, "#3");
+                       Assert.AreEqual (typeof (InheritsFromClassWithNullableDateTime), siblingProperty.ReflectedType, "#4");
+               }
+               
+       
+               public class ClassWithNullableDateTime
+               {
+                       public DateTime? Property1 { get; set; }
+               }
+       
+               public class InheritsFromClassWithNullableDateTime : ClassWithNullableDateTime
+               {
+               }
+
+               public static int ThrowingProperty {
+                       get {
+                               throw new ObjectDisposedException("TestClass");
+                       }
+               }
+
+               [Test]
+               public void GetException () {
+                       var prop = typeof(PropertyInfoTest).GetProperty("ThrowingProperty");
+                       try {
+                               prop.GetValue (null, null);
+                               Assert.Fail ();
+                       } catch (TargetInvocationException ex) {
+                               Assert.IsTrue (ex.InnerException is ObjectDisposedException);
+                       }
+               }
+
+               public class DefaultValueTest
+               {
+                       public string this[int val, string param = "test"]
+                       {
+                               get{ return val + param; }
+                       }
+               }
+
+
+               [Test]
+               public void PropertyWithDefaultValue ()
+               {
+                       var parameters = typeof (DefaultValueTest).GetProperty ("Item").GetIndexParameters ();
+                       var defaultParam = parameters[parameters.Length - 1];
+                       Assert.AreEqual ("param", defaultParam.Name, "#1");
+                       Assert.AreEqual ("test", defaultParam.DefaultValue, "#2");
+               }
        }
 }