| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // PropertyInfoTest.cs - NUnit Test Cases for PropertyInfo
- //
- // Author:
- // Gert Driesen ([email protected])
- //
- // (C) 2004 Novell
- //
- using System;
- using System.Reflection;
- using NUnit.Framework;
- namespace MonoTests.System.Reflection
- {
- [TestFixture]
- public class PropertyInfoTest
- {
- [Test]
- public void GetAccessorsTest()
- {
- Type type = typeof(TestClass);
- PropertyInfo property = type.GetProperty ("ReadOnlyProperty");
- MethodInfo[] methods = property.GetAccessors (true);
- Assert.AreEqual (1, methods.Length, "GetAccessors#1");
- Assert.IsNotNull (methods[0], "GetAccessors#2");
-
- }
- [Test]
- [Category ("NotWorking")]
- public void GetCustomAttributesInherited ()
- {
- Type derived = typeof (Derived);
- PropertyInfo p = derived.GetProperty ("P");
- Assert.AreEqual (1, p.GetCustomAttributes (true).Length);
- }
- public class ThisAttribute : Attribute {
- }
- class Base {
- [ThisAttribute]
- public virtual string P {
- get { return null; }
- set { }
- }
- }
- class Derived : Base {
- public override string P {
- get { return null; }
- set { }
- }
- }
- #if NET_2_0
- public class A<T>
- {
- public string Property {
- get { return typeof (T).FullName; }
- }
- }
- public int? nullable_field;
- public int? NullableProperty {
- get { return nullable_field; }
- set { nullable_field = value; }
- }
- [Test]
- public void NullableTests ()
- {
- PropertyInfoTest t = new PropertyInfoTest ();
- PropertyInfo pi = typeof(PropertyInfoTest).GetProperty("NullableProperty");
- pi.SetValue (t, 100, null);
- Assert.AreEqual (100, pi.GetValue (t, null));
- pi.SetValue (t, null, null);
- Assert.AreEqual (null, pi.GetValue (t, null));
- }
- [Test]
- public void Bug77160 ()
- {
- object instance = new A<string> ();
- Type type = instance.GetType ();
- PropertyInfo property = type.GetProperty ("Property");
- Assert.AreEqual (typeof (string).FullName, property.GetValue (instance, null));
- }
- #endif
- private class TestClass
- {
- public string ReadOnlyProperty
- {
- get { return string.Empty; }
- }
- }
- }
- }
|