New test.
[mono.git] / mcs / class / corlib / Test / System.Reflection / PropertyInfoTest.cs
1 //
2 // PropertyInfoTest.cs - NUnit Test Cases for PropertyInfo
3 //
4 // Author:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (C) 2004 Novell 
8 //
9
10 using System;
11 using System.Reflection; 
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Reflection
16 {
17         [TestFixture]
18         public class PropertyInfoTest
19         {
20                 [Test]
21                 public void GetAccessorsTest()
22                 {
23                         Type type = typeof(TestClass);
24                         PropertyInfo property = type.GetProperty ("ReadOnlyProperty");
25                         MethodInfo[] methods = property.GetAccessors (true);
26
27                         Assert.AreEqual (1, methods.Length, "GetAccessors#1");
28                         Assert.IsNotNull (methods[0], "GetAccessors#2");
29                                                 
30                 }
31
32 #if NET_2_0
33
34                 public class A<T> 
35                 {
36                         public string Property {
37                                 get { return typeof (T).FullName; }
38                         }
39                 }
40
41                 public int? nullable_field;
42
43                 public int? NullableProperty {
44                         get { return nullable_field; }
45                         set { nullable_field = value; }
46                 }
47
48                 [Test]
49                 public void NullableTests ()
50                 {
51                         PropertyInfoTest t = new PropertyInfoTest ();
52
53                         PropertyInfo pi = typeof(PropertyInfoTest).GetProperty("NullableProperty");
54
55                         pi.SetValue (t, 100, null);
56                         Assert.AreEqual (100, pi.GetValue (t, null));
57                         pi.SetValue (t, null, null);
58                         Assert.AreEqual (null, pi.GetValue (t, null));
59                 }
60
61                 [Test]
62                 public void Bug77160 ()
63                 {
64                         object instance = new A<string> ();
65                         Type type = instance.GetType ();
66                         PropertyInfo property = type.GetProperty ("Property");
67                         Assert.AreEqual (typeof (string).FullName, property.GetValue (instance, null));
68                 }
69 #endif
70
71                 private class TestClass 
72                 {
73                         public string ReadOnlyProperty 
74                         {
75                                 get { return string.Empty; }
76                         }
77                 }
78         }
79 }