public void ReflectionUtilVerifyInterfaceNullInterfaceTest()
 {
     ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
       ReflectionUtil.VerifyInterface(testData, null);
 }
        public void ReflectionUtilVerifyInterfaceTest()
        {
            ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };

              bool result = ReflectionUtil.VerifyInterface(testData, typeof(ITestLookupData));
              Assert.IsTrue(result);

              result = ReflectionUtil.VerifyInterface(testData, typeof(IDisposable));
              Assert.IsFalse(result);
        }
        public void ReflectionUtilSetPropertyValueTest()
        {
            ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };

              bool result = ReflectionUtil.SetPropertyValue(testData, "Description", "This is a unit test");
              Assert.IsTrue(result);
              Assert.AreEqual("This is a unit test", testData.Description);
        }
 public void ReflectionUtilVerifyInterfaceNonInterfaceTest()
 {
     ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
       ReflectionUtil.VerifyInterface(testData, typeof(string));
 }
 public void ReflectionUtilIsClassOfTypeTest()
 {
     ReflectionTestData data = new ReflectionTestData();
       Assert.IsTrue(ReflectionUtil.IsClassOfType(data.GetType(), typeof(ReflectionTestData)));
       Assert.IsTrue(ReflectionUtil.IsClassOfType(data.GetType(), typeof(ITestLookupData)));
       Assert.IsFalse(ReflectionUtil.IsClassOfType(data.GetType(), typeof(int)));
 }
        public void ReflectionUtilGetPropertyValueTest()
        {
            ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
              testData.SubData = new ReflectionTestSubData();
              testData.SubData.ItemValue = 15.7;
              object propertyValue;

              bool result = ReflectionUtil.GetPropertyValue(testData, "SubData.ItemValue", out propertyValue);
              Assert.IsTrue(result);
              Assert.IsNotNull(propertyValue);
              Assert.AreEqual(15.7, propertyValue);

              object fieldValue;
              result = ReflectionUtil.GetPropertyValue(testData, "PrimaryKey", out fieldValue);
              Assert.IsTrue(result);
              Assert.IsNotNull(fieldValue);
              Assert.AreEqual(22, fieldValue);

              int primaryKeyValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badPrimaryKey", out primaryKeyValue);
              Assert.IsFalse(result);
              Assert.AreEqual(Int32.MinValue, primaryKeyValue);
              result = ReflectionUtil.GetPropertyValue(testData, "PrimaryKey", out primaryKeyValue);
              Assert.IsTrue(result);
              Assert.AreEqual(22, primaryKeyValue);

              decimal primaryDecimalKeyValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badPrimaryKey", out primaryDecimalKeyValue);
              Assert.IsFalse(result);
              Assert.AreEqual(Decimal.MinValue, primaryDecimalKeyValue);
              result = ReflectionUtil.GetPropertyValue(testData, "PrimaryKey", out primaryDecimalKeyValue);
              Assert.IsTrue(result);
              Assert.AreEqual(22, primaryDecimalKeyValue);

              Guid labelIdentifierValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badLabelIdentifier", out labelIdentifierValue);
              Assert.IsFalse(result);
              Assert.AreEqual(Guid.Empty, labelIdentifierValue);
              result = ReflectionUtil.GetPropertyValue(testData, "LabelIdentifier", out labelIdentifierValue);
              Assert.IsTrue(result);
              Assert.AreEqual(ReflectionTestData.DefaultLabelIdentifier, labelIdentifierValue);

              string nameValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badName", out nameValue);
              Assert.IsFalse(result);
              Assert.IsNull(nameValue);
              result = ReflectionUtil.GetPropertyValue(testData, "Name", out nameValue);
              Assert.IsTrue(result);
              Assert.AreEqual("Test", nameValue);

              DateTime dateValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badCreatedDate", out dateValue);
              Assert.IsFalse(result);
              Assert.AreEqual(DateTime.MinValue, dateValue);
              result = ReflectionUtil.GetPropertyValue(testData, "CreatedDate", out dateValue);
              Assert.IsTrue(result);
              Assert.AreEqual(ReflectionTestData.DefaultCreatedDate, dateValue);

              double doubleValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badPercentage", out doubleValue);
              Assert.IsFalse(result);
              Assert.AreEqual(Double.MinValue, doubleValue);
              result = ReflectionUtil.GetPropertyValue(testData, "Percentage", out doubleValue);
              Assert.IsTrue(result);
              Assert.AreEqual(3.5, doubleValue);

              bool boolValue;
              result = ReflectionUtil.GetPropertyValue(testData, "badIsActive", out boolValue);
              Assert.IsFalse(result);
              Assert.IsFalse(boolValue);
              result = ReflectionUtil.GetPropertyValue(testData, "IsActive", out boolValue);
              Assert.IsTrue(result);
              Assert.IsTrue(boolValue);
        }
        public void ReflectionUtilGetPropertyTypeTest()
        {
            ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
              testData.SubData = new ReflectionTestSubData();
              testData.SubData.ItemValue = 15.7;
              Type propertyType;

              bool result = ReflectionUtil.GetPropertyType(testData, "SubData.ItemValue", out propertyType);
              Assert.IsTrue(result);
              Assert.IsNotNull(propertyType);
              Assert.AreEqual(typeof(double), propertyType);

              result = ReflectionUtil.GetPropertyType(testData, "BadProperty", out propertyType);
              Assert.IsFalse(result);
              Assert.IsNull(propertyType);
        }
        public void ReflectionUtilGetPropertyAttributeTest()
        {
            ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
              testData.SubData = new ReflectionTestSubData();
              testData.SubData.ItemValue = 15.7;
              Attribute propertyAttribute;

              bool result = ReflectionUtil.GetPropertyAttribute(testData, "SubData.ItemValue", typeof(ExcludeFromCodeCoverageAttribute), out propertyAttribute);
              Assert.IsTrue(result);
              Assert.IsNotNull(propertyAttribute);

              result = ReflectionUtil.GetPropertyAttribute(testData, "SubData", typeof(ExcludeFromCodeCoverageAttribute), out propertyAttribute);
              Assert.IsFalse(result);
              Assert.IsNull(propertyAttribute);

              result = ReflectionUtil.GetPropertyAttribute(testData, "SubData.ItemValue", typeof(SerializableAttribute), out propertyAttribute);
              Assert.IsFalse(result);
              Assert.IsNull(propertyAttribute);
        }
        public void ReflectionUtilGetFieldValueNegativeTest()
        {
            ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test.BadName" };
              object fieldValue;

              bool result = ReflectionUtil.GetFieldValue(null, "PrimaryKey", out fieldValue);
              Assert.IsFalse(result);

              int primaryKeyValue;
              result = ReflectionUtil.GetFieldValue(testData, "badPrimaryKey", out primaryKeyValue);
              Assert.IsFalse(result);
        }