コード例 #1
0
        public void InlcludeAncestors()
        {
            const string          defName     = "foo";
            const string          placeholder = "${name}";
            MutablePropertyValues pvs         = new MutablePropertyValues();


            const string theProperty = "name";

            pvs.Add(theProperty, placeholder);
            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs);

            IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>();

            Expect.Call(mock.GetObjectDefinitionNames(true)).Return(new string[] { defName });
            Expect.Call(mock.GetObjectDefinition(defName, true)).Return(def);
            mocks.ReplayAll();

            VariablePlaceholderConfigurer vpc = new VariablePlaceholderConfigurer();

            vpc.IgnoreUnresolvablePlaceholders = true;
            vpc.VariableSource   = new DictionaryVariableSource(new string[] { "name", "Erich" });
            vpc.IncludeAncestors = true;

            vpc.PostProcessObjectFactory(mock);

            mocks.VerifyAll();
        }
        public void ThrowsOnMissingVariableSources()
        {
            StaticApplicationContext      ac   = new StaticApplicationContext();
            VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer();

            try
            {
                vphc.PostProcessObjectFactory(ac.ObjectFactory);
                Assert.Fail("Expected ArgumentException not thrown.");
            }
            catch (ArgumentException)
            {
            }
        }
コード例 #3
0
        public void ThrowsOnMissingVariableSources()
        {
            StaticApplicationContext ac = new StaticApplicationContext();
            VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer();

            try
            {
                vphc.PostProcessObjectFactory(ac.ObjectFactory);
                Assert.Fail("Expected ArgumentException not thrown.");
            }
            catch (ArgumentException)
            {
            }
        }
コード例 #4
0
 public void ThrowsOnInvalidVariableSourcesElement()
 {
     StaticApplicationContext ac = new StaticApplicationContext();
     VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer();
     vphc.VariableSources = new ArrayList(new object[] { new object() });
     
     try
     {
         vphc.PostProcessObjectFactory(ac.ObjectFactory);
         Assert.Fail("Expected ArgumentException not thrown.");
     }
     catch (ArgumentException)
     {
     }
 }
        public void ThrowsOnInvalidVariableSourcesElement()
        {
            StaticApplicationContext      ac   = new StaticApplicationContext();
            VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer();

            vphc.VariableSources = new ArrayList(new object[] { new object() });

            try
            {
                vphc.PostProcessObjectFactory(ac.ObjectFactory);
                Assert.Fail("Expected ArgumentException not thrown.");
            }
            catch (ArgumentException)
            {
            }
        }
        public void NestedResolution()
        {
            DefaultListableObjectFactory of  = new DefaultListableObjectFactory();
            MutablePropertyValues        pvs = new MutablePropertyValues();

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

            IList variableSources = new ArrayList();

            variableSources.Add(new DictionaryVariableSource(new string[] { "name", "${nickname}" }));
            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("nickname-value", rod.PropertyValues.GetPropertyValue("NameProperty").Value);
        }
        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);
        }
コード例 #8
0
        public void ChainedResolution()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("name", "${name}");
            pvs.Add("nickname", "${nickname}");
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

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

            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            Assert.AreEqual("name-value", tb1.Name);
            Assert.AreEqual("nickname-value", tb1.Nickname);
        }
        public void IgnoresUnresolvableVariable()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();

            pvs.Add("name", "${name}");
            pvs.Add("nickname", "${nickname}");
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            VariablePlaceholderConfigurer vpc = new VariablePlaceholderConfigurer();

            vpc.IgnoreUnresolvablePlaceholders = true;
            vpc.VariableSource = new DictionaryVariableSource(new string[] { "name", "Erich" });
            ac.AddObjectFactoryPostProcessor(vpc);

            ac.Refresh();

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

            Assert.AreEqual("Erich", tb1.Name);
            Assert.AreEqual("${nickname}", tb1.Nickname);
        }
        public void ChainedResolution()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();

            pvs.Add("name", "${name}");
            pvs.Add("nickname", "${nickname}");
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            IList variableSources = new ArrayList();

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

            ac.AddObjectFactoryPostProcessor(vphc);
            ac.Refresh();

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

            Assert.AreEqual("name-value", tb1.Name);
            Assert.AreEqual("nickname-value", tb1.Nickname);
        }
コード例 #11
0
 public TextProcessor(VariablePlaceholderConfigurer owner, IVariableSource variableSource)
 {
     this.owner          = owner;
     this.variableSource = variableSource;
 }
コード例 #12
0
 public TextProcessor(VariablePlaceholderConfigurer owner, IVariableSource variableSource)
 {
     this.owner = owner;
     this.variableSource = variableSource;
 }
コード例 #13
0
        public void InlcludeAncestors()
        {
            const string defName = "foo";
            const string placeholder = "${name}";
            MutablePropertyValues pvs = new MutablePropertyValues();


            const string theProperty = "name";
            pvs.Add(theProperty, placeholder);
            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs);

            IConfigurableListableObjectFactory mock = mocks.StrictMock<IConfigurableListableObjectFactory>();
            Expect.Call(mock.GetObjectDefinitionNames(true)).Return(new string[] { defName });
            Expect.Call(mock.GetObjectDefinition(defName, true)).Return(def);
            mocks.ReplayAll();

            VariablePlaceholderConfigurer vpc = new VariablePlaceholderConfigurer();
            vpc.IgnoreUnresolvablePlaceholders = true;
            vpc.VariableSource = new DictionaryVariableSource(new string[] { "name", "Erich" });
            vpc.IncludeAncestors = true;

            vpc.PostProcessObjectFactory(mock);

            mocks.VerifyAll();            
        }
コード例 #14
0
        public void IgnoresUnresolvableVariable()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("name", "${name}");
            pvs.Add("nickname", "${nickname}");
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            VariablePlaceholderConfigurer vpc = new VariablePlaceholderConfigurer();
            vpc.IgnoreUnresolvablePlaceholders = true;
            vpc.VariableSource = new DictionaryVariableSource(new string[] { "name", "Erich" });
            ac.AddObjectFactoryPostProcessor(vpc);

            ac.Refresh();

            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            Assert.AreEqual("Erich", tb1.Name);
            Assert.AreEqual("${nickname}", tb1.Nickname);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }