public void GetMember_GenericTypeMismatch_ReturnsNull() { var types = new TypeMemberInfoCollection(); Assert.IsNull(types.GetMember<PropertyInfo>(typeof(ContentTypeDescriptor), "IsTypeOf")); Assert.IsNull(types.GetMember<MethodInfo>(typeof(ContentTypeDescriptor), "AttributeDescriptors")); }
public void GetMember_MethodInfoByKey_ReturnsValue() { var types = new TypeMemberInfoCollection(); Assert.IsNotNull(types.GetMember<MethodInfo>(typeof(ContentTypeDescriptor), "GetWebPath")); Assert.IsNull(types.GetMember<MethodInfo>(typeof(ContentTypeDescriptor), "AttributeDescriptors")); }
public void GetMember_PropertyInfoByKey_ReturnsValue() { var types = new TypeMemberInfoCollection(); Assert.IsNotNull(types.GetMember<PropertyInfo>(typeof(ContentTypeDescriptor), "Key")); Assert.IsNotNull(types.GetMember<PropertyInfo>(typeof(ContentTypeDescriptor), "AttributeDescriptors")); Assert.IsNull(types.GetMember<PropertyInfo>(typeof(ContentTypeDescriptor), "InvalidPropertyName")); }
public void SetMethod_Integer_SetsValue() { var types = new TypeMemberInfoCollection(); var source = new MethodBasedViewModel(); var isInvalidSet = types.SetMethodValue(source, "BogusMethod", "123"); Assert.IsFalse(isInvalidSet); }
public void SetPropertyValue_InvalidProperty_ReturnsFalse() { var types = new TypeMemberInfoCollection(); var topic = TopicFactory.Create("Test", "ContentType"); var isInvalidPropertySet = types.SetPropertyValue(topic, "InvalidProperty", "Invalid"); Assert.IsFalse(isInvalidPropertySet); }
public void SetPropertyValue_Boolean_SetsValue() { var types = new TypeMemberInfoCollection(); var topic = TopicFactory.Create("Test", "ContentType"); types.SetPropertyValue(topic, "IsHidden", "1"); Assert.IsTrue(topic.IsHidden); }
public void GetMembers_PropertyInfo_ReturnsProperties() { var types = new TypeMemberInfoCollection(); var properties = types.GetMembers<PropertyInfo>(typeof(ContentTypeDescriptor)); Assert.IsTrue(properties.Contains("Key")); Assert.IsTrue(properties.Contains("AttributeDescriptors")); Assert.IsFalse(properties.Contains("IsTypeOf")); Assert.IsFalse(properties.Contains("InvalidPropertyName")); }
public void SetMethod_InvalidValue_DoesNotSetValue() { var types = new TypeMemberInfoCollection(); var source = new MethodBasedViewModel(); var isValueSet = types.SetMethodValue(source, "SetMethod", "ABC"); var value = types.GetMethodValue(source, "GetMethod")?? 0; Assert.IsFalse(isValueSet); Assert.IsTrue(value is int); Assert.AreEqual<int>(0, (int)value); }
public void SetPropertyValue_ReflectionPerformance() { var totalIterations = 1; var types = new TypeMemberInfoCollection(); var topic = TopicFactory.Create("Test", "ContentType"); int i; for (i = 0; i < totalIterations; i++) { types.SetPropertyValue(topic, "Key", "Key" + i); } Assert.AreEqual<string>("Key" + (i-1), topic.Key); }
public void SetPropertyValue_Key_SetsValue() { var types = new TypeMemberInfoCollection(); var topic = TopicFactory.Create("Test", "ContentType"); var isKeySet = types.SetPropertyValue(topic, "Key", "NewKey"); var key = types.GetPropertyValue(topic, "Key", typeof(string)).ToString(); Assert.IsTrue(isKeySet); Assert.AreEqual<string>("NewKey", topic.Key); Assert.AreEqual<string>("NewKey", key); }
public void SetPropertyValue_DateTime_SetsValue() { var types = new TypeMemberInfoCollection(); var topic = TopicFactory.Create("Test", "ContentType"); var isDateSet = types.SetPropertyValue(topic, "LastModified", "June 3, 2008"); isDateSet = types.SetPropertyValue(topic, "LastModified", "2008-06-03") && isDateSet; isDateSet = types.SetPropertyValue(topic, "LastModified", "06/03/2008") && isDateSet; var lastModified = DateTime.Parse( types.GetPropertyValue(topic, "LastModified", typeof(DateTime)).ToString(), CultureInfo.InvariantCulture ); Assert.IsTrue(isDateSet); Assert.AreEqual<DateTime>(new(2008, 6, 3), topic.LastModified); Assert.AreEqual<DateTime>(new(2008, 6, 3), lastModified); }