private static LambdaDynamicTypeConfiguration<TestModelWithDynamicTypeDescriptionAttribute> GetDynamicTypeDescription()
        {
            var config = new LambdaDynamicTypeConfiguration<TestModelWithDynamicTypeDescriptionAttribute>();
            config.ForProperty(m => m.LastName).RemoveAttribute(typeof (StringLengthAttribute));

            return config;
        }
        public void GetProperties_ReplaceStringLengthInConfiguration_StringLenghtHasDifferentMinAndMax()
        {
            /* ARRANGE */
            var config = new LambdaDynamicTypeConfiguration<TestModel>();
            config.ForProperty(m => m.LastName)
                  .RemoveAttribute(typeof (StringLengthAttribute))
                  .AddAttribute(() => new StringLengthAttribute(30) {MinimumLength = 10});

            var descriptor = new LambdaTypeDescriptor(config);

            /* ACT */
            PropertyDescriptorCollection properties = descriptor.GetProperties();

            /* ASSERT */
            Assert.IsTrue(properties.Count == 3);

            // FirstName
            PropertyDescriptor firstName = properties[0];
            Assert.AreEqual("FirstName", firstName.Name);
            Assert.AreEqual("First name", firstName.DisplayName);

            var required = firstName.Attributes[typeof (RequiredAttribute)] as RequiredAttribute;
            Assert.IsNotNull(required);
            var displayName = firstName.Attributes[typeof (DisplayNameAttribute)] as DisplayNameAttribute;
            Assert.IsNotNull(displayName);
            Assert.AreEqual("First name", displayName.DisplayName);

            // LastName
            PropertyDescriptor lastName = properties[1];
            Assert.AreEqual("LastName", lastName.Name);

            var stringLength = lastName.Attributes[typeof (StringLengthAttribute)] as StringLengthAttribute;
            Assert.IsNotNull(stringLength);
            Assert.AreEqual(30, stringLength.MaximumLength); // DIFFERENCE HERE
            Assert.AreEqual(10, stringLength.MinimumLength); // DIFFERENCE HERE

            // Age
            PropertyDescriptor age = properties[2];
            Assert.AreEqual("Age", age.Name);

            var range = age.Attributes[typeof (RangeAttribute)] as RangeAttribute;
            Assert.IsNotNull(range);
            Assert.AreEqual(0, range.Minimum);
            Assert.AreEqual(120, range.Maximum);
        }
        public void GetProperties_RemoveRequiredAttributeInConfiguration_AttributeNotReturned()
        {
            /* ARRANGE */
            var config = new LambdaDynamicTypeConfiguration<TestModel>();
            config.ForProperty(m => m.FirstName).RemoveAttribute(typeof (RequiredAttribute));
            var descriptor = new LambdaTypeDescriptor(config);

            /* ACT */
            PropertyDescriptorCollection properties = descriptor.GetProperties();

            /* ASSERT */
            Assert.IsTrue(properties.Count == 3);

            // FirstName
            PropertyDescriptor firstName = properties[0];
            Assert.AreEqual("FirstName", firstName.Name);
            Assert.AreEqual("First name", firstName.DisplayName);

            var required = firstName.Attributes[typeof (RequiredAttribute)] as RequiredAttribute;
            Assert.IsNull(required); // SHOULD BE NULL!
            var displayName = firstName.Attributes[typeof (DisplayNameAttribute)] as DisplayNameAttribute;
            Assert.IsNotNull(displayName);
            Assert.AreEqual("First name", displayName.DisplayName);

            // LastName
            PropertyDescriptor lastName = properties[1];
            Assert.AreEqual("LastName", lastName.Name);

            var stringLength = lastName.Attributes[typeof (StringLengthAttribute)] as StringLengthAttribute;
            Assert.IsNotNull(stringLength);
            Assert.AreEqual(20, stringLength.MaximumLength);
            Assert.AreEqual(5, stringLength.MinimumLength);

            // Age
            PropertyDescriptor age = properties[2];
            Assert.AreEqual("Age", age.Name);

            var range = age.Attributes[typeof (RangeAttribute)] as RangeAttribute;
            Assert.IsNotNull(range);
            Assert.AreEqual(0, range.Minimum);
            Assert.AreEqual(120, range.Maximum);
        }
        public void GetProperties_RemoveMiddlePropertyInConfiguration_MiddlePropertyNotReturned()
        {
            /* ARRANGE */
            var config = new LambdaDynamicTypeConfiguration<TestModel>();
            config.ForProperty(m => m.LastName).RemoveProperty();

            var descriptor = new LambdaTypeDescriptor(config);

            /* ACT */
            PropertyDescriptorCollection properties = descriptor.GetProperties();

            /* ASSERT */
            Assert.IsTrue(properties.Count == 2);

            // FirstName
            PropertyDescriptor firstName = properties[0];
            Assert.AreEqual("FirstName", firstName.Name);
            Assert.AreEqual("First name", firstName.DisplayName);

            var required = firstName.Attributes[typeof (RequiredAttribute)] as RequiredAttribute;
            Assert.IsNotNull(required);
            var displayName = firstName.Attributes[typeof (DisplayNameAttribute)] as DisplayNameAttribute;
            Assert.IsNotNull(displayName);
            Assert.AreEqual("First name", displayName.DisplayName);

            // Age
            PropertyDescriptor age = properties[1];
            Assert.AreEqual("Age", age.Name);

            var range = age.Attributes[typeof (RangeAttribute)] as RangeAttribute;
            Assert.IsNotNull(range);
            Assert.AreEqual(0, range.Minimum);
            Assert.AreEqual(120, range.Maximum);
        }
        public void GetProperties_RemoveFirstPropertyInConfiguration_FirstPropertyNotReturned()
        {
            /* ARRANGE */
            var config = new LambdaDynamicTypeConfiguration<TestModel>();
            config.ForProperty(m => m.FirstName).RemoveProperty();

            var descriptor = new LambdaTypeDescriptor(config);

            /* ACT */
            PropertyDescriptorCollection properties = descriptor.GetProperties();

            /* ASSERT */
            Assert.IsTrue(properties.Count == 2);

            // LastName
            PropertyDescriptor lastName = properties[0];
            Assert.AreEqual("LastName", lastName.Name);

            var stringLength = lastName.Attributes[typeof (StringLengthAttribute)] as StringLengthAttribute;
            Assert.IsNotNull(stringLength);
            Assert.AreEqual(20, stringLength.MaximumLength);
            Assert.AreEqual(5, stringLength.MinimumLength);

            // Age
            PropertyDescriptor age = properties[1];
            Assert.AreEqual("Age", age.Name);

            var range = age.Attributes[typeof (RangeAttribute)] as RangeAttribute;
            Assert.IsNotNull(range);
            Assert.AreEqual(0, range.Minimum);
            Assert.AreEqual(120, range.Maximum);
        }