public void GetAccessors() { var nonPublicSetMethod = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Private, parameters: new[] { _indexParameter, _valueParameter }); var property = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod, setMethod: nonPublicSetMethod); Assert.That(property.GetAccessors(true), Is.EquivalentTo(new[] { _getMethod, nonPublicSetMethod })); Assert.That(property.GetAccessors(false), Is.EquivalentTo(new[] { _getMethod })); }
public void GetCustomAttributeData() { var customAttributes = new[] { CustomAttributeDeclarationObjectMother.Create() }; var property = CustomPropertyInfoObjectMother.Create(customAttributes: customAttributes); var propertyInstantiation = new PropertyOnTypeInstantiation(_declaringType, property, _getMethod, _setMethod); Assert.That(propertyInstantiation.GetCustomAttributeData(), Is.EqualTo(customAttributes)); }
public void UnsupportedMembers() { var property = CustomPropertyInfoObjectMother.Create(); UnsupportedMemberTestHelper.CheckProperty(() => property.ReflectedType, "ReflectedType"); UnsupportedMemberTestHelper.CheckMethod(() => property.SetValue(null, null, null), "SetValue"); UnsupportedMemberTestHelper.CheckMethod(() => property.GetValue(null, null), "GetValue"); }
public new void ToString() { var type = ReflectionObjectMother.GetSomeType(); var returnParameter = CustomParameterInfoObjectMother.Create(type: type); var method = CustomMethodInfoObjectMother.Create(returnParameter: returnParameter); var name = "MyProperty"; var property = CustomPropertyInfoObjectMother.Create(name: name, getMethod: method); Assert.That(property.ToString(), Is.EqualTo(type.Name + " MyProperty")); }
public void CustomAttributeMethods() { var customAttribute = CustomAttributeDeclarationObjectMother.Create(typeof(ObsoleteAttribute)); var property = CustomPropertyInfoObjectMother.Create(customAttributes: new[] { customAttribute }); Assert.That(property.GetCustomAttributes(false).Select(a => a.GetType()), Is.EqualTo(new[] { typeof(ObsoleteAttribute) })); Assert.That(property.GetCustomAttributes(typeof(NonSerializedAttribute), false), Is.Empty); Assert.That(property.IsDefined(typeof(ObsoleteAttribute), false), Is.True); Assert.That(property.IsDefined(typeof(NonSerializedAttribute), false), Is.False); }
public void SetUp() { _indexParameter = CustomParameterInfoObjectMother.Create(); _declaringType = TypeInstantiationObjectMother.Create(); _getMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, typeof(GenericType <>).GetMethod("get_Item")); _setMethod = MethodOnTypeInstantiationObjectMother.Create(_declaringType, typeof(GenericType <>).GetMethod("set_Item")); _originalProperty = CustomPropertyInfoObjectMother.Create( indexParameters: new[] { _indexParameter }, getMethod: _getMethod, setMethod: _setMethod); _property = new PropertyOnTypeInstantiation(_declaringType, _originalProperty, _getMethod, _setMethod); }
public void GetGetMethod() { var nonPublicMethod = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Private, returnParameter: _valueParameter); var property1 = CustomPropertyInfoObjectMother.Create(getMethod: nonPublicMethod); var property2 = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod); var property3 = CustomPropertyInfoObjectMother.Create(getMethod: null, setMethod: _setMethod); Assert.That(property1.GetGetMethod(true), Is.SameAs(nonPublicMethod)); Assert.That(property1.GetGetMethod(false), Is.Null); Assert.That(property2.GetGetMethod(true), Is.SameAs(_getMethod)); Assert.That(property2.GetGetMethod(false), Is.SameAs(_getMethod)); Assert.That(property3.GetGetMethod(true), Is.Null); Assert.That(property3.GetGetMethod(false), Is.Null); }
public void SetUp() { _declaringType = CustomTypeObjectMother.Create(); _type = ReflectionObjectMother.GetSomeType(); _valueParameter = CustomParameterInfoObjectMother.Create(type: _type); var indexParameterType = ReflectionObjectMother.GetSomeOtherType(); _indexParameter = CustomParameterInfoObjectMother.Create(type: indexParameterType); _getMethod = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter }, returnParameter: _valueParameter); _setMethod = CustomMethodInfoObjectMother.Create(attributes: MethodAttributes.Public, parameters: new[] { _indexParameter, _valueParameter }); _readOnlyProperty = CustomPropertyInfoObjectMother.Create(getMethod: _getMethod); _writeOnlyProperty = CustomPropertyInfoObjectMother.Create(setMethod: _setMethod); }
public void ToDebugString() { var declaringType = CustomTypeObjectMother.Create(); var type = ReflectionObjectMother.GetSomeType(); var returnParameter = CustomParameterInfoObjectMother.Create(type: type); var method = CustomMethodInfoObjectMother.Create(returnParameter: returnParameter); var name = "MyProperty"; var property = CustomPropertyInfoObjectMother.Create(declaringType, name, getMethod: method); // Note: ToDebugString is defined in CustomFieldInfo base class. Assertion.IsNotNull(property.DeclaringType); var declaringTypeName = property.DeclaringType.Name; var propertyTypeName = property.PropertyType.Name; var propertyName = property.Name; var expected = "TestableCustomProperty = \"" + propertyTypeName + " " + propertyName + "\", DeclaringType = \"" + declaringTypeName + "\""; Assert.That(property.ToDebugString(), Is.EqualTo(expected)); }