public void ChangesSince()
        {
            IDictionary <string, object> map = new Dictionary <string, object>();
            PropertyValue propName           = new PropertyValue("Name", "Fiona Apple");

            map.Add(propName.Name, propName.Value);
            map.Add("Age", 24);
            MutablePropertyValues props    = new MutablePropertyValues(map);
            MutablePropertyValues newProps = new MutablePropertyValues(map);

            // change the name... this is the change we'll be looking for
            newProps.SetPropertyValueAt(new PropertyValue(propName.Name, "Naomi Woolf"), 0);
            IPropertyValues changes = newProps.ChangesSince(props);

            Assert.AreEqual(1, changes.PropertyValues.Count);
            // the name was changed, so its the name property that should be in the changed list
            Assert.IsTrue(changes.Contains("name"));

            newProps.Add(new PropertyValue("Commentator", "Naomi Woolf"));
            changes = newProps.ChangesSince(props);
            Assert.AreEqual(2, changes.PropertyValues.Count);
            // the Commentator was added, so its the Commentator property that should be in the changed list
            Assert.IsTrue(changes.Contains("commentator"));
            // the name was changed, so its the name property that should be in the changed list
            Assert.IsTrue(changes.Contains("name"));
        }
示例#2
0
        /// <summary>
        /// Post-process the given property values before the factory applies them
        /// to the given object.  Checks for the attribute specified by this PostProcessor's RequiredAttributeType.
        /// </summary>
        /// <param name="pvs">The property values that the factory is about to apply (never <code>null</code>).</param>
        /// <param name="pis">The relevant property infos for the target object (with ignored
        /// dependency types - which the factory handles specifically - already filtered out)</param>
        /// <param name="objectInstance">The object instance created, but whose properties have not yet
        /// been set.</param>
        /// <param name="objectName">Name of the object.</param>
        /// <returns>
        /// The actual property values to apply to the given object (can be the
        /// passed-in PropertyValues instances or null to skip property population.
        /// </returns>
        /// <exception cref="ObjectInitializationException">If a required property value has not been specified
        /// in the configuration metadata.</exception>
        public override IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, IList <PropertyInfo> pis, object objectInstance, string objectName)
        {
            if (!validatedObjectNames.Contains(objectName))
            {
                List <string> invalidProperties = new List <string>();

                foreach (PropertyInfo pi in pis)
                {
                    if (IsRequiredProperty(pi) && !pvs.Contains(pi.Name))
                    {
                        invalidProperties.Add(pi.Name);
                    }
                }
                if (invalidProperties.Count != 0)
                {
                    throw new ObjectInitializationException(
                              BuildExceptionMessage(invalidProperties, objectName));
                }
                validatedObjectNames.Add(objectName);
            }
            return(pvs);
        }
        /// <summary>
        /// Post-process the given property values before the factory applies them
        /// to the given object.  Checks for the attribute specified by this PostProcessor's RequiredAttributeType.
        /// </summary>
        /// <param name="pvs">The property values that the factory is about to apply (never <code>null</code>).</param>
        /// <param name="pis">The relevant property infos for the target object (with ignored
        /// dependency types - which the factory handles specifically - already filtered out)</param>
        /// <param name="objectInstance">The object instance created, but whose properties have not yet
        /// been set.</param>
        /// <param name="objectName">Name of the object.</param>
        /// <returns>
        /// The actual property values to apply to the given object (can be the
        /// passed-in PropertyValues instances or null to skip property population.
        /// </returns>
        /// <exception cref="ObjectInitializationException">If a required property value has not been specified
        /// in the configuration metadata.</exception>
        public override IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, PropertyInfo[] pis, object objectInstance,
                                                                  string objectName)
        {
            if (!validatedObjectNames.Contains(objectName))
            {
                ArrayList invalidProperties = new ArrayList();

                foreach (PropertyInfo pi in pis)
                {
                    if (IsRequiredProperty(pi) && !pvs.Contains(pi.Name))
                    {
                        invalidProperties.Add(pi.Name);
                    }
                }
                if (invalidProperties.Count != 0)
                {
                    throw new ObjectInitializationException(
                              BuildExceptionMessage((string[])invalidProperties.ToArray(typeof(string)), objectName));
                }
                validatedObjectNames.Add(objectName);
            }
            return(pvs);
        }
        /// <summary>
        /// Post-process the given property values before the factory applies them
        /// to the given object.  Checks for the attribute specified by this PostProcessor's RequiredAttributeType.
        /// </summary>
        /// <param name="pvs">The property values that the factory is about to apply (never <code>null</code>).</param>
        /// <param name="pis">The relevant property infos for the target object (with ignored
        /// dependency types - which the factory handles specifically - already filtered out)</param>
        /// <param name="objectInstance">The object instance created, but whose properties have not yet
        /// been set.</param>
        /// <param name="objectName">Name of the object.</param>
        /// <returns>
        /// The actual property values to apply to the given object (can be the
        /// passed-in PropertyValues instances or null to skip property population.
        /// </returns>
        /// <exception cref="ObjectInitializationException">If a required property value has not been specified
        /// in the configuration metadata.</exception>
        public override IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, PropertyInfo[] pis, object objectInstance,
                                                         string objectName)
        {
            if (!validatedObjectNames.Contains(objectName))
            {
                ArrayList invalidProperties = new ArrayList();

                foreach (PropertyInfo pi in pis)
                {
                    if (IsRequiredProperty(pi) && !pvs.Contains(pi.Name))
                    {
                        invalidProperties.Add(pi.Name);
                    }
                }
                if (invalidProperties.Count != 0)
                {
                    throw new ObjectInitializationException(
                        BuildExceptionMessage((string[]) invalidProperties.ToArray(typeof (string)), objectName));
                }
                validatedObjectNames.Add(objectName);
            }
            return pvs;
        }
        /// <summary>
        /// Post-process the given property values before the factory applies them
        /// to the given object.  Checks for the attribute specified by this PostProcessor's RequiredAttributeType.
        /// </summary>
        /// <param name="pvs">The property values that the factory is about to apply (never <code>null</code>).</param>
        /// <param name="pis">The relevant property infos for the target object (with ignored
        /// dependency types - which the factory handles specifically - already filtered out)</param>
        /// <param name="objectInstance">The object instance created, but whose properties have not yet
        /// been set.</param>
        /// <param name="objectName">Name of the object.</param>
        /// <returns>
        /// The actual property values to apply to the given object (can be the
        /// passed-in PropertyValues instances or null to skip property population.
        /// </returns>
        /// <exception cref="ObjectInitializationException">If a required property value has not been specified
        /// in the configuration metadata.</exception>
        public override IPropertyValues PostProcessPropertyValues(IPropertyValues pvs, IList<PropertyInfo> pis, object objectInstance, string objectName)
        {
            if (!validatedObjectNames.Contains(objectName))
            {
                List<string> invalidProperties = new List<string>();

                foreach (PropertyInfo pi in pis)
                {
                    if (IsRequiredProperty(pi) && !pvs.Contains(pi.Name))
                    {
                        invalidProperties.Add(pi.Name);
                    }
                }
                if (invalidProperties.Count != 0)
                {
                    throw new ObjectInitializationException(
                        BuildExceptionMessage(invalidProperties, objectName));
                }
                validatedObjectNames.Add(objectName);
            }
            return pvs;
        }