コード例 #1
0
        public void SunnyDay()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();

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

            IList variableSources             = new ArrayList();
            CommandLineArgsVariableSource vs1 = new CommandLineArgsVariableSource(
                new string[] { "program.exe", "file.txt", "/name:Aleks Seovic", "/framework:Oragon.Spring.NET" });

            variableSources.Add(vs1);

            ConfigSectionVariableSource vs2 = new ConfigSectionVariableSource();

            vs2.SectionName = "DaoConfiguration";
            variableSources.Add(vs2);


            pvs = new MutablePropertyValues();
            pvs.Add("VariableSources", variableSources);

            ac.RegisterSingleton("configurer", typeof(VariablePlaceholderConfigurer), pvs);
            ac.Refresh();

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

            Assert.AreEqual(1000, tb1.Age);
            Assert.AreEqual("Aleks Seovic", tb1.Name);
        }
コード例 #2
0
        public void TestVariablesResolution()
        {
            CommandLineArgsVariableSource vs = new CommandLineArgsVariableSource(
                new string[] { "program.exe", "file.txt", "/name:Aleks Seovic", "/framework:Oragon.Spring.NET" });

            // existing vars
            Assert.AreEqual("Oragon.Spring.NET", vs.ResolveVariable("FRAMEWORK"));
            Assert.AreEqual("Oragon.Spring.NET", vs.ResolveVariable("framework"));
            Assert.AreEqual("Aleks Seovic", vs.ResolveVariable("name"));
            Assert.AreEqual("Aleks Seovic", vs.ResolveVariable("NAME"));

            // non-existant variable
            Assert.IsNull(vs.ResolveVariable("dummy"));
        }
コード例 #3
0
        public void TestVariablesResolutionWithCustomPrefixAndSeparator()
        {
            CommandLineArgsVariableSource vs = new CommandLineArgsVariableSource(
                new string[] { "program.exe", "file.txt", "--Name=Aleks Seovic", "--Framework=Oragon.Spring.NET" });

            vs.ArgumentPrefix = "--";
            vs.ValueSeparator = "=";

            // existing vars
            Assert.AreEqual("Oragon.Spring.NET", vs.ResolveVariable("FRAMEWORK"));
            Assert.AreEqual("Oragon.Spring.NET", vs.ResolveVariable("framework"));
            Assert.AreEqual("Aleks Seovic", vs.ResolveVariable("name"));
            Assert.AreEqual("Aleks Seovic", vs.ResolveVariable("NAME"));

            // non-existant variable
            Assert.IsNull(vs.ResolveVariable("dummy"));
        }
コード例 #4
0
        public void TestLiveVariablesResolutionWithTestDriven()
        {
            CommandLineArgsVariableSource vs = new CommandLineArgsVariableSource();

            Assert.IsTrue(((string)vs.ResolveVariable("AssemblyName")).StartsWith("TestDriven.TestRunner.Server"));
        }