public void InstantiationIsImplictlyNotToParent()
        {
            RuntimeObjectReference ror = new RuntimeObjectReference("foo");

            Assert.IsFalse(ror.IsToParent,
                           "IsToParent property must default to false if not " +
                           "using the explicit variant of the ctor.");
        }
 /// <summary>
 /// Resolves the given value taken from an object definition according to its type
 /// </summary>
 /// <param name="value">the value to resolve</param>
 /// <returns>the resolved value</returns>
 protected virtual object ResolveValue(object value)
 {
     if (value is IObjectDefinition)
     {
         VisitObjectDefinition((IObjectDefinition)value);
     }
     else if (value is ObjectDefinitionHolder)
     {
         VisitObjectDefinition(((ObjectDefinitionHolder)value).ObjectDefinition);
     }
     else if (value is RuntimeObjectReference)
     {
         RuntimeObjectReference ror = (RuntimeObjectReference)value;
         //name has to be of string type.
         string newObjectName = ResolveStringValue(ror.ObjectName);
         if (!newObjectName.Equals(ror.ObjectName))
         {
             return(new RuntimeObjectReference(newObjectName));
         }
     }
     else if (value is ManagedList)
     {
         VisitManagedList((ManagedList)value);
     }
     else if (value is ManagedSet)
     {
         VisitManagedSet((ManagedSet)value);
     }
     else if (value is ManagedDictionary)
     {
         VisitManagedDictionary((ManagedDictionary)value);
     }
     else if (value is NameValueCollection)
     {
         VisitNameValueCollection((NameValueCollection)value);
     }
     else if (value is TypedStringValue)
     {
         TypedStringValue typedStringValue = (TypedStringValue)value;
         String           stringValue      = typedStringValue.Value;
         if (stringValue != null)
         {
             String visitedString = ResolveStringValue(stringValue);
             typedStringValue.Value = visitedString;
         }
     }
     else if (value is string)
     {
         return(ResolveStringValue((string)value));
     }
     else if (value is ExpressionHolder)
     {
         ExpressionHolder holder = (ExpressionHolder)value;
         string           newExpressionString = ResolveStringValue(holder.ExpressionString);
         return(new ExpressionHolder(newExpressionString));
     }
     return(value);
 }
        public void SunnyDay()
        {
            StaticApplicationContext ac = new StaticApplicationContext();


            MutablePropertyValues pvs = new MutablePropertyValues();

            pvs.Add("age", "${age}");
            RootObjectDefinition def
                = new RootObjectDefinition("${fqn}", new ConstructorArgumentValues(), pvs);

            ac.RegisterObjectDefinition("tb3", def);



            pvs = new MutablePropertyValues();
            pvs.Add("age", "${age}");
            pvs.Add("name", "name${var}${");
            pvs.Add("spouse", new RuntimeObjectReference("${ref}"));
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            ConstructorArgumentValues cas = new ConstructorArgumentValues();

            cas.AddIndexedArgumentValue(1, "${age}");
            cas.AddGenericArgumentValue("${var}name${age}");

            pvs = new MutablePropertyValues();
            ArrayList friends = new ManagedList();

            friends.Add("na${age}me");
            friends.Add(new RuntimeObjectReference("${ref}"));
            pvs.Add("friends", friends);

            ISet someSet = new ManagedSet();

            someSet.Add("na${age}me");
            someSet.Add(new RuntimeObjectReference("${ref}"));
            pvs.Add("someSet", someSet);

            IDictionary someDictionary = new ManagedDictionary();

            someDictionary["key1"] = new RuntimeObjectReference("${ref}");
            someDictionary["key2"] = "${age}name";
            MutablePropertyValues innerPvs = new MutablePropertyValues();

            someDictionary["key3"] = new RootObjectDefinition(typeof(TestObject), innerPvs);
            someDictionary["key4"] = new ChildObjectDefinition("tb1", innerPvs);
            pvs.Add("someMap", someDictionary);

            RootObjectDefinition definition = new RootObjectDefinition(typeof(TestObject), cas, pvs);

            ac.DefaultListableObjectFactory.RegisterObjectDefinition("tb2", definition);

            pvs = new MutablePropertyValues();
            pvs.Add("Properties", "<spring-config><add key=\"age\" value=\"98\"/><add key=\"var\" value=\"${m}var\"/><add key=\"ref\" value=\"tb2\"/><add key=\"m\" value=\"my\"/><add key=\"fqn\" value=\"Oragon.Spring.Objects.TestObject, Oragon.Spring.Core.Tests\"/></spring-config>");
            ac.RegisterSingleton("configurer", typeof(PropertyPlaceholderConfigurer), pvs);
            ac.Refresh();

            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            TestObject tb2 = (TestObject)ac.GetObject("tb2");
            TestObject tb3 = (TestObject)ac.GetObject("tb3");

            Assert.AreEqual(98, tb1.Age);
            Assert.AreEqual(98, tb2.Age);
            Assert.AreEqual(98, tb3.Age);
            Assert.AreEqual("namemyvar${", tb1.Name);
            Assert.AreEqual("myvarname98", tb2.Name);
            Assert.AreEqual(tb2, tb1.Spouse);
            Assert.AreEqual(2, tb2.Friends.Count);
            IEnumerator ie = tb2.Friends.GetEnumerator();

            ie.MoveNext();
            Assert.AreEqual("na98me", ie.Current);
            ie.MoveNext();
            Assert.AreEqual(tb2, ie.Current);
            Assert.AreEqual(2, tb2.SomeSet.Count);
            Assert.IsTrue(tb2.SomeSet.Contains("na98me"));
            Assert.IsTrue(tb2.SomeSet.Contains(tb2));
            Assert.AreEqual(4, tb2.SomeMap.Count);
            Assert.AreEqual(tb2, tb2.SomeMap["key1"]);
            Assert.AreEqual("98name", tb2.SomeMap["key2"]);
            TestObject inner1 = (TestObject)tb2.SomeMap["key3"];
            TestObject inner2 = (TestObject)tb2.SomeMap["key4"];

            Assert.AreEqual(0, inner1.Age);
            Assert.AreEqual(null, inner1.Name);
            Assert.AreEqual(98, inner2.Age);
            Assert.AreEqual("namemyvar${", inner2.Name);
        }
 /// <summary>
 /// Determines whether the specified RuntimeObjectReference is equal to the current RuntimeObjectReference.
 /// </summary>
 /// <returns>true if the specified RuntimeObjectReference is equal to the current RuntimeObjectReference; otherwise, false.</returns>
 protected bool Equals(RuntimeObjectReference other)
 {
     return(string.Equals(_objectName, other._objectName) && _isToParent.Equals(other._isToParent));
 }