예제 #1
0
 public void ReflectionUtilVerifyInterfaceNullInterfaceTest()
 {
     ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
       ReflectionUtil.VerifyInterface(testData, null);
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public void ReflectionUtilVerifyInterfaceNonInterfaceTest()
 {
     ReflectionTestData testData = new ReflectionTestData() { Index = 22, Name = "Test" };
       ReflectionUtil.VerifyInterface(testData, typeof(string));
 }
예제 #5
0
 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)));
 }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }