public void TestEquals()
 {
     PropertyValue one = new PropertyValue("Age", 12);
     PropertyValue two = new PropertyValue("Age", 12);
     Assert.AreEqual(one, two);
     Assert.AreEqual(one.GetHashCode(), two.GetHashCode());
     Assert.AreEqual(one, one);
     Assert.IsFalse(one.Equals("Foo"));
 }
        public void ChangesSince()
        {
            IDictionary map = new Hashtable ();
            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.Length);
            // 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.Length);
            // 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"));
        }
 public void TestToString()
 {
     PropertyValue one = new PropertyValue("Age", 12);
     Assert.AreEqual("PropertyValue: name='Age'; value=[12].", one.ToString());
 }
 public void Instantiation()
 {
     PropertyValue val = new PropertyValue("Age", 12);
     Assert.AreEqual("Age", val.Name);
     Assert.AreEqual(12, val.Value);
 }
 public void RemoveByPropertyValue () 
 {
     MutablePropertyValues props = new MutablePropertyValues ();
     PropertyValue propName = new PropertyValue ("Name", "Fiona Apple");
     props.Add (propName);
     props.Add (new PropertyValue ("Age", 24));
     Assert.AreEqual (2, props.PropertyValues.Count);
     props.Remove (propName);
     Assert.AreEqual (1, props.PropertyValues.Count);
 }
 /// <summary>
 /// Merges the value of the supplied 'new' <see cref="PropertyValue"/> with that of
 /// the current <see cref="PropertyValue"/> if merging is supported and enabled.
 /// </summary>
 /// <see cref="IMergable"/>
 /// <param name="newPv">The new pv.</param>
 /// <param name="currentPv">The current pv.</param>
 /// <returns>The possibly merged PropertyValue</returns>
 private PropertyValue MergeIfRequired(PropertyValue newPv, PropertyValue currentPv)
 {
     object val = newPv.Value;
     IMergable mergable = val as IMergable;
     if (mergable != null)
     {
         if (mergable.MergeEnabled)
         {
             object merged = mergable.Merge(currentPv.Value);
             return new PropertyValue(newPv.Name, merged);
         }
     }
     return newPv;
 }
 /// <summary>
 /// Modify a <see cref="Spring.Objects.PropertyValue"/> object held in this object. Indexed from 0.
 /// </summary>
 public void SetPropertyValueAt(PropertyValue pv, int i)
 {
     propertyValuesList [i] = pv;
 }
 /// <summary>
 /// Remove the given <see cref="Spring.Objects.PropertyValue"/>, if contained.
 /// </summary>
 /// <param name="pv">
 /// The <see cref="Spring.Objects.PropertyValue"/> to remove.
 /// </param>
 public void Remove(PropertyValue pv)
 {
     propertyValuesList.Remove (pv);
 }
 /// <summary>
 /// Add the supplied <see cref="Spring.Objects.PropertyValue"/> object,
 /// replacing any existing one for the respective property.
 /// </summary>
 /// <param name="pv">
 /// The <see cref="Spring.Objects.PropertyValue"/> object to add.
 /// </param>
 public void Add(PropertyValue pv)
 {
     for (int i = 0; i < propertyValuesList.Count; ++i)
     {
         PropertyValue currentPv = (PropertyValue) propertyValuesList [i];
         if (currentPv.Name.Equals (pv.Name))
         {
             pv = MergeIfRequired(pv, currentPv);
             propertyValuesList[i] = pv;
             return ;
         }
     }
     propertyValuesList.Add (pv);
 }
        /// <summary>
        /// Apply the given property values, resolving any runtime references
        /// to other objects in this object factory.
        /// </summary>
        /// <param name="name">
        /// The object name passed for better exception information.
        /// </param>
        /// <param name="definition">
        /// The definition of the named object.
        /// </param>
        /// <param name="wrapper">
        /// The <see cref="Spring.Objects.IObjectWrapper"/> wrapping the target object.
        /// </param>
        /// <param name="properties">
        /// The new property values.
        /// </param>
        /// <remarks>
        /// <p>
        /// Must use deep copy, so that we don't permanently modify this property.
        /// </p>
        /// </remarks>
        protected void ApplyPropertyValues(string name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties)
        {
            if (properties == null || properties.PropertyValues.Length == 0)
            {
                return;
            }
            ObjectDefinitionValueResolver valueResolver = CreateValueResolver();

            MutablePropertyValues deepCopy = new MutablePropertyValues(properties);
            PropertyValue[] copiedProperties = deepCopy.PropertyValues;
            for (int i = 0; i < copiedProperties.Length; ++i)
            {
                PropertyValue copiedProperty = copiedProperties[i];
                //(string name, RootObjectDefinition definition, string argumentName, object argumentValue)
                object value = valueResolver.ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value);
                // object value = ResolveValueIfNecessary(name, definition, copiedProperty.Name, copiedProperty.Value);
                PropertyValue propertyValue = new PropertyValue(copiedProperty.Name, value, copiedProperty.Expression);
                // update mutable copy...
                deepCopy.SetPropertyValueAt(propertyValue, i);
            }
            // set the (possibly resolved) deep copy properties...
            try
            {
                wrapper.SetPropertyValues(deepCopy);
            }
            catch (ObjectsException ex)
            {
                // improve the message by showing the context...
                throw new ObjectCreationException(definition.ResourceDescription, name, "Error setting property values: " + ex.Message, ex);
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Sets a property value.
 /// </summary>
 /// <remarks>
 /// <p>
 /// <b>This is the preferred way to update an individual property.</b>
 /// </p>
 /// </remarks>
 /// <param name="pv">
 /// The object containing new property value.
 /// </param>
 public virtual void SetPropertyValue(PropertyValue pv)
 {
     SetPropertyValue(pv.Expression, pv.Value);
 }
Esempio n. 12
0
        public void TestToString()
        {
            PropertyValue one = new PropertyValue("Age", 12);

            Assert.AreEqual("PropertyValue: name='Age'; value=[12].", one.ToString());
        }