public void GetObjectDefinitionResolvesAliases()
        {
            const string TheParentsAlias = "theParentsAlias";
            const int ExpectedAge = 31;
            const string ExpectedName = "Rick Evans";

            RootObjectDefinition parentDef = new RootObjectDefinition(typeof(TestObject));
            parentDef.IsAbstract = true;
            parentDef.PropertyValues.Add("name", ExpectedName);
            parentDef.PropertyValues.Add("age", ExpectedAge);

            ChildObjectDefinition childDef = new ChildObjectDefinition(TheParentsAlias);

            DefaultListableObjectFactory fac = new DefaultListableObjectFactory();

            fac.RegisterObjectDefinition("parent", parentDef);
            fac.RegisterAlias("parent", TheParentsAlias);

            IObjectDefinition od = fac.GetObjectDefinition(TheParentsAlias);
            Assert.IsNotNull(od);
        }
        public void ParsesObjectAttributes()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
            reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>  
	<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='false' abstract='true' />
	<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='true' abstract='false' lazy-init='true' 
        autowire='no' dependency-check='simple'
        depends-on='test1' 
        init-method='init'
        destroy-method='destroy'
    />
</objects>
"));
            AbstractObjectDefinition od1 = (AbstractObjectDefinition)of.GetObjectDefinition("test1");
            Assert.IsFalse(od1.IsSingleton);
            Assert.IsTrue(od1.IsAbstract);
            Assert.IsFalse(od1.IsLazyInit);

            AbstractObjectDefinition od2 = (AbstractObjectDefinition)of.GetObjectDefinition("test2");
            Assert.IsTrue(od2.IsSingleton);
            Assert.IsFalse(od2.IsAbstract);
            Assert.IsTrue(od2.IsLazyInit);
            Assert.AreEqual(AutoWiringMode.No, od2.AutowireMode);
            Assert.AreEqual("init", od2.InitMethodName);
            Assert.AreEqual("destroy", od2.DestroyMethodName);
            Assert.AreEqual(1, od2.DependsOn.Length);
            Assert.AreEqual("test1", od2.DependsOn[0]);
            Assert.AreEqual(DependencyCheckingMode.Simple, od2.DependencyCheck);
        }
        public void ChainedResolutionWithNullValues()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("NameProperty", "${name}");
            pvs.Add("NickNameProperty", "${nickname}");
            of.RegisterObjectDefinition("tb1", new RootObjectDefinition("typename", null, pvs));

            IList variableSources = new ArrayList();
            variableSources.Add(new DictionaryVariableSource(new string[] { "name", "name-value", "nickname", null }));
            variableSources.Add(new DictionaryVariableSource(new string[] { "nickname", "nickname-value" }));
            VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(variableSources);

            vphc.PostProcessObjectFactory(of);
            RootObjectDefinition rod = (RootObjectDefinition)of.GetObjectDefinition("tb1");
            Assert.AreEqual("name-value", rod.PropertyValues.GetPropertyValue("NameProperty").Value);
            Assert.AreEqual(null, rod.PropertyValues.GetPropertyValue("NickNameProperty").Value);
        }
        public void ParsesAutowireCandidate()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
            reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' default-autowire-candidates='test1*,test4*'>  
	<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' />
	<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='false' />
	<object id='test3' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='true' />
	<object id='test4' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='default' />
	<object id='test5' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='default' />
</objects>
"));
            var od = (AbstractObjectDefinition)of.GetObjectDefinition("test1");
            Assert.That(od.IsAutowireCandidate, Is.True, "No attribute set should default to true");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test2");
            Assert.That(od.IsAutowireCandidate, Is.False, "Specifically attribute set to false should set to false");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test3");
            Assert.That(od.IsAutowireCandidate, Is.True, "Specifically attribute set to true should set to false");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test4");
            Assert.That(od.IsAutowireCandidate, Is.True, "Attribute set to default should check pattern and return true");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test5");
            Assert.That(od.IsAutowireCandidate, Is.False, "Attribute set to default should check pattern and return false");
        }
        public void MultiResolution()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();
            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("Greeting", "Hello ${firstname} ${lastname}!");
            of.RegisterObjectDefinition("tb1", new RootObjectDefinition("typename", null, pvs));

            IList variableSources = new ArrayList();
            variableSources.Add(new DictionaryVariableSource(new string[] { "firstname", "FirstName" }));
            variableSources.Add(new DictionaryVariableSource(new string[] { "lastname", "LastName" }));
            VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(variableSources);
            vphc.PostProcessObjectFactory(of);

            RootObjectDefinition rod = (RootObjectDefinition)of.GetObjectDefinition("tb1");
            Assert.AreEqual("Hello FirstName LastName!", rod.PropertyValues.GetPropertyValue("Greeting").Value);
        }