public void SetValue_SetsValueOfDynamicallyAddedProperty_StoresTheValue()
        {
            /* ARRANGE */
            const string propertyName = "SecondLastName";
            const string expectedPropertyValue = "2nd last name";

            var config = new LambdaDynamicTypeConfiguration<TestModelWithPropertyBag>();
            config.AddProperty(propertyName, typeof (string))
                  .AddAttribute(() => new RequiredAttribute())
                  .AddAttribute(() => new StringLengthAttribute(25) {MinimumLength = 7});

            var descriptor = new LambdaTypeDescriptor(config);
            PropertyDescriptorCollection properties = descriptor.GetProperties();
            PropertyDescriptor secondLastName = properties[3];
                // this is our internal DynamicPropertyDescriptor, visible as base class.

            var testModel = new TestModelWithPropertyBag();

            /* ACT */
            secondLastName.SetValue(testModel, "2nd last name");

            /* ASSERT */
            var actualPropertyValue = ((ISimplePropertyBag) testModel)[propertyName] as string;

            Assert.AreEqual(expectedPropertyValue, actualPropertyValue);
        }
        public void GetProperties_AddPropertyInConfigurationOnModelWithoutPropertyBag_NoChangesToTypeMetadata()
        {
            /* ARRANGE */
            var config = new LambdaDynamicTypeConfiguration<TestModel>();
            config.AddProperty("SecondLastName", typeof (string))
                  .AddAttribute(() => new RequiredAttribute())
                  .AddAttribute(() => new StringLengthAttribute(25) {MinimumLength = 7});

            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(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);
        }