public void TestCanExecuteGenericMethodOnObject() { ReflectTestClass myTestClass = new ReflectTestClass(); //test can do method with void return type myTestClass.HasMethodExecuted = false; Assert.IsFalse(myTestClass.HasMethodExecuted); object returnValue = ReflectionUtility.Reflect.InvokeGenericMethodOnObject(myTestClass, "ExecuteMe", typeof(ReflectTestClass), new object[] { new ReflectTestClass("Hello") }); Assert.IsNull(returnValue); Assert.IsTrue(myTestClass.HasMethodExecuted); //test can do method with return type T and no params myTestClass.HasMethodExecuted = false; Assert.IsFalse(myTestClass.HasMethodExecuted); returnValue = ReflectionUtility.Reflect.InvokeGenericMethodOnObject(myTestClass, "ExecuteMe", typeof(ReflectTestClass), null); Assert.IsNotNull(returnValue); Assert.IsInstanceOf <ReflectTestClass>(returnValue); Assert.IsTrue(myTestClass.HasMethodExecuted); //test can do method with return type T and params myTestClass.HasMethodExecuted = false; Assert.IsFalse(myTestClass.HasMethodExecuted); returnValue = ReflectionUtility.Reflect.InvokeGenericMethodOnObject(myTestClass, "ExecuteMe", typeof(ReflectTestClass), new object[] { new ReflectTestClass("Hello"), new ReflectTestClass("goodBye") }); Assert.IsNotNull(returnValue); Assert.IsInstanceOf <ReflectTestClass>(returnValue); Assert.IsTrue(myTestClass.HasMethodExecuted); }
public void TestCanGetPrivatePropertyValue() { ReflectTestClass myTestClass = new ReflectTestClass("Bob"); string propertyValue = ReflectionUtility.Reflect.GetPropertyValue <String>(myTestClass, "NamePropertyPrivate"); Assert.AreEqual("Bob", propertyValue); }
public void TestCanSetPrivatePropertyValue() { ReflectTestClass myTestClass = new ReflectTestClass(); Assert.IsNullOrEmpty(ReflectionUtility.Reflect.GetPropertyValue <String>(myTestClass, "NamePropertyPrivate")); ReflectionUtility.Reflect.AssignPropertyValue(myTestClass, "NamePropertyPrivate", "Bob"); Assert.AreEqual("Bob", ReflectionUtility.Reflect.GetPropertyValue <String>(myTestClass, "NamePropertyPrivate")); }
public void TestCanGetPrivateFieldValue() { ReflectTestClass myTestClass = new ReflectTestClass("Bob"); string fieldValue = ReflectionUtility.Reflect.GetFieldValue <String>(myTestClass, "NameFieldPrivate"); Assert.AreEqual("Bob", fieldValue); }
public void TestCanSetPublicPropertyValue() { ReflectTestClass myTestClass = new ReflectTestClass(); Assert.IsNullOrEmpty(myTestClass.NamePropertyPublic); ReflectionUtility.Reflect.AssignPropertyValue(myTestClass, "NamePropertyPublic", "Bob"); Assert.IsNotNullOrEmpty(myTestClass.NamePropertyPublic); Assert.AreEqual("Bob", myTestClass.NamePropertyPublic); }
public void TestCanGetPrivateFieldInfo() { ReflectTestClass myTestClass = new ReflectTestClass("Bob"); FieldInfo fieldInfo = ReflectionUtility.Reflect.GetField(myTestClass, "NameFieldPrivate"); Assert.IsNotNull(fieldInfo); Assert.AreEqual("Bob", fieldInfo.GetValue(myTestClass).ToString()); }
public void TestCanGetPublicPropertyValue() { ReflectTestClass myTestClass = new ReflectTestClass(); myTestClass.NamePropertyPublic = "Bob"; Assert.IsNotNullOrEmpty(myTestClass.NamePropertyPublic); string propertyValue = ReflectionUtility.Reflect.GetPropertyValue <String>(myTestClass, "NamePropertyPublic"); Assert.AreEqual("Bob", propertyValue); }
public void TestCanGetTypeOfValueForGivenObject() { ReflectTestClass myTestClass = new ReflectTestClass(); Type publicPropertyType = ReflectionUtility.Reflect.GetValueType(myTestClass, "NamePropertyPublic"); Assert.IsTrue(publicPropertyType == typeof(String)); Type publicFieldType = ReflectionUtility.Reflect.GetValueType(myTestClass, "NameFieldPublic"); Assert.IsTrue(publicFieldType == typeof(String)); }
public void TestCanGetPrivatePropertyInfo() { ReflectTestClass myTestClass = new ReflectTestClass("Bob"); PropertyInfo propertyInfo = ReflectionUtility.Reflect.GetProperty(myTestClass, "NamePropertyPrivate"); Assert.IsNotNull(propertyInfo); object value = propertyInfo.GetValue(myTestClass, null); Assert.IsNotNull(value); Assert.AreEqual("Bob", value.ToString()); }
public void TestCanGetPropertyOrFieldValue() { ReflectTestClass myTestClass = new ReflectTestClass("Bob"); string fieldValue = ReflectionUtility.Reflect.GetValue <String>(myTestClass, "NameFieldPrivate"); Assert.IsNotNullOrEmpty(fieldValue); Assert.AreEqual("Bob", fieldValue); string propertyValue = ReflectionUtility.Reflect.GetValue <String>(myTestClass, "NamePropertyPrivate"); Assert.IsNotNullOrEmpty(propertyValue); Assert.AreEqual("Bob", propertyValue); }