Inheritance: PropertyDescriptorPropInfo
 public void Test_Construct_WithPropInfor_ShouldSetPropInfo()
 {
     //---------------Set up test pack-------------------
     PropertyInfo propertyInfo = new Habanero.Testability.Helpers.FakePropertyInfo();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
     //---------------Test Result -----------------------
     Assert.IsNotNull(propDescriptor);
     Assert.AreSame(propertyInfo, propDescriptor.GetPropertyInfo());
 }
        public void Test_Construct_WithPropInfor_ShouldSetPropInfo()
        {
            //---------------Set up test pack-------------------
            PropertyInfo propertyInfo = new Habanero.Testability.Helpers.FakePropertyInfo();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Test Result -----------------------
            Assert.IsNotNull(propDescriptor);
            Assert.AreSame(propertyInfo, propDescriptor.GetPropertyInfo());
        }
        public void Test_Construct_WithPropInfo_ShouldSetName()
        {
            //---------------Set up test pack-------------------
            var          propName     = GetRandomString();
            PropertyInfo propertyInfo = new FakePropertyInfo(propName);

            //---------------Assert Precondition----------------
            Assert.AreEqual(propName, propertyInfo.Name);
            //---------------Execute Test ----------------------
            var propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Test Result -----------------------
            Assert.AreEqual(propName, propDescriptor.Name);
        }
        public void Test_DisplayName_ShouldBePropertyName_CamelCaseDelimited()
        {
            //---------------Set up test pack-------------------
            const string       propName       = "ThisIsCamelCased";
            var                propertyInfo   = new FakePropertyInfo(propName);
            PropertyDescriptor propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.AreEqual(propName, propertyInfo.Name);
            //---------------Execute Test ----------------------
            var actualPropDescriptorDisplayName = propDescriptor.DisplayName;

            //---------------Test Result -----------------------
            Assert.AreEqual("This Is Camel Cased", actualPropDescriptorDisplayName);
        }
        public void Test_PropertyType_ShouldReturnPropertyTypePropInfo()
        {
            //---------------Set up test pack-------------------
            var expectedPropType = typeof(int);
            var propertyInfo     = new FakePropertyInfo(GetRandomString(), expectedPropType);

            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedPropType, propertyInfo.PropertyType);
            //---------------Execute Test ----------------------
            var propertyType = propDescriptor.PropertyType;

            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropType, propertyType);
        }
        public void Test_ComponentType_ShouldReturnGridColumnsClassDefsClassType()
        {
            //---------------Set up test pack-------------------
            var propertyInfo          = new FakePropertyInfo();
            var expectedComponentType = typeof(FakeBO);

            propertyInfo.SetReflectedType(expectedComponentType);
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo.ReflectedType);
            //---------------Execute Test ----------------------
            var componentType = propDescriptor.ComponentType;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedComponentType, componentType);
        }
        public void Test_IsReadOnly_WhenNotHasSetMethod_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            var propertyInfo = MockRepository.GenerateStub <FakePropertyInfo>();

            propertyInfo.Stub(info => info.Name).Return(GetRandomString());
            propertyInfo.Stub(info => info.GetSetMethod(false)).Return(null);
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNull(propertyInfo.GetSetMethod());
            //---------------Execute Test ----------------------
            var isReadOnly = propDescriptor.IsReadOnly;

            //---------------Test Result -----------------------
            Assert.IsTrue(isReadOnly, "If has NO setter should be ReadOnly.");
        }
        public void Test_IsReadOnly_WhenHasSetMethod_AndReadOnlyAttributeFalse_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            var propertyInfo = GetMockPropertyInfo();

            propertyInfo.Stub(info => info.GetCustomAttributes(typeof(ReadOnlyAttribute), true)).Return(new object[] { new ReadOnlyAttribute(false) });
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Assert Precondition----------------
            Assert.IsNotNull(propertyInfo.GetSetMethod());
            Assert.IsFalse(propertyInfo.GetAttribute <ReadOnlyAttribute>().IsReadOnly);
            //---------------Execute Test ----------------------
            var isReadOnly = propDescriptor.IsReadOnly;

            //---------------Test Result -----------------------
            Assert.IsFalse(isReadOnly, "If has setter and ReadOnlyAttribute false so should not be ReadOnly.");
        }
        public void Test_GetValue_WhenComponentNotCorrectType_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName");
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                propDescriptor.GetValue(100);
                Assert.Fail("Expected to throw an InvalidCastException");
            }
            //---------------Test Result -----------------------
            catch (InvalidCastException ex)
            {
                StringAssert.Contains("You cannot GetValue since the component is not of type ", ex.Message);
            }
        }
        public void Test_GetValue_WhenComponentNull_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            var propertyInfo = new FakePropertyInfo();
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
            object x = null;

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                propDescriptor.GetValue(x);
                Assert.Fail("Expected to throw an ArgumentNullException");
            }
            //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("component", ex.ParamName);
                StringAssert.Contains("Value cannot be null.", ex.Message);
            }
        }
 public void Test_DisplayName_ShouldBePropertyName_CamelCaseDelimited()
 {
     //---------------Set up test pack-------------------
     const string propName = "ThisIsCamelCased";
     var propertyInfo = new FakePropertyInfo(propName);
     PropertyDescriptor propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.AreEqual(propName, propertyInfo.Name);
     //---------------Execute Test ----------------------
     var actualPropDescriptorDisplayName = propDescriptor.DisplayName;
     //---------------Test Result -----------------------
     Assert.AreEqual("This Is Camel Cased", actualPropDescriptorDisplayName);
 }
 public void Test_IsReadOnly_WhenHasSetMethod_AndReadOnlyAttributeFalse_ShouldReturnTrue()
 {
     //---------------Set up test pack-------------------
     var propertyInfo = GetMockPropertyInfo();
     propertyInfo.Stub(info => info.GetCustomAttributes(typeof(ReadOnlyAttribute), true)).Return(new object[]{new ReadOnlyAttribute(false)});
     PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(propertyInfo.GetSetMethod());
     Assert.IsFalse(propertyInfo.GetAttribute<ReadOnlyAttribute>().IsReadOnly);
     //---------------Execute Test ----------------------
     var isReadOnly = propDescriptor.IsReadOnly;
     //---------------Test Result -----------------------
     Assert.IsFalse(isReadOnly, "If has setter and ReadOnlyAttribute false so should not be ReadOnly.");
 }        
        public void Test_PropertyType_ShouldReturnPropertyTypePropInfo()
        {
            //---------------Set up test pack-------------------
            var expectedPropType = typeof(int);
            var propertyInfo = new FakePropertyInfo(GetRandomString(), expectedPropType);

            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
            //---------------Assert Precondition----------------
            Assert.AreEqual(expectedPropType, propertyInfo.PropertyType);
            //---------------Execute Test ----------------------
            var propertyType = propDescriptor.PropertyType;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropType, propertyType);
        }
 public void Test_Construct_WithPropInfo_ShouldSetName()
 {
     //---------------Set up test pack-------------------
     var propName = GetRandomString();
     PropertyInfo propertyInfo = new FakePropertyInfo(propName);
     //---------------Assert Precondition----------------
     Assert.AreEqual(propName, propertyInfo.Name);
     //---------------Execute Test ----------------------
     var propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
     //---------------Test Result -----------------------
     Assert.AreEqual(propName, propDescriptor.Name);
 }
 public void Test_IsReadOnly_WhenNotHasSetMethod_ShouldReturnFalse()
 {
     //---------------Set up test pack-------------------
     var propertyInfo = MockRepository.GenerateStub<FakePropertyInfo>();
     propertyInfo.Stub(info => info.Name).Return(GetRandomString());
     propertyInfo.Stub(info => info.GetSetMethod(false)).Return(null);
     PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsNull(propertyInfo.GetSetMethod());
     //---------------Execute Test ----------------------
     var isReadOnly = propDescriptor.IsReadOnly;
     //---------------Test Result -----------------------
     Assert.IsTrue(isReadOnly, "If has NO setter should be ReadOnly.");
 }
        public void Test_GetValue_WhenComponentNull_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            var propertyInfo = new FakePropertyInfo();
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
            object x = null;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                propDescriptor.GetValue(x);
                Assert.Fail("Expected to throw an ArgumentNullException");
            }
            //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("component", ex.ParamName);
                StringAssert.Contains("Value cannot be null.", ex.Message);
            }
        }
        public void Test_GetValue_WhenComponentNotCorrectType_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            var propertyInfo = typeof(FakeBO).GetProperty("FakeBOName");
            PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            try
            {
                propDescriptor.GetValue(100);
                Assert.Fail("Expected to throw an InvalidCastException");
            }
            //---------------Test Result -----------------------
            catch (InvalidCastException ex)
            {
                StringAssert.Contains("You cannot GetValue since the component is not of type ", ex.Message);
            }
        }
 public void Test_ComponentType_ShouldReturnGridColumnsClassDefsClassType()
 {
     //---------------Set up test pack-------------------
     var propertyInfo = new FakePropertyInfo();
     var expectedComponentType = typeof (FakeBO);
     propertyInfo.SetReflectedType(expectedComponentType);
     PropertyDescriptorPropInfo propDescriptor = new PropertyDescriptorPropInfoSpy(propertyInfo);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(propertyInfo.ReflectedType);
     //---------------Execute Test ----------------------
     var componentType = propDescriptor.ComponentType;
     //---------------Test Result -----------------------
     Assert.AreSame(expectedComponentType, componentType);
 }