Ejemplo n.º 1
0
        public void AddRangeOfIndexedArgumentValues()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            values.AddIndexedArgumentValue(1, DBNull.Value);
            values.AddIndexedArgumentValue(2, "Foo");
            values.AddIndexedArgumentValue(3, 3);
            new ConstructorArgumentValues(values);
            Assert.IsFalse(values.Empty, "Added three indexed values(as a range), but the collection is sayin' it's empty.");
            Assert.AreEqual(3, values.ArgumentCount, "Added three indexed values(as a range), but the collection ain't sayin' that it's got 3 elements in it.");
            Assert.AreEqual(3, values.IndexedArgumentValues.Count, "Added three indexed values(as a range), but the collection of indexed values ain't sayin' that it's got 3 elements in it.");
        }
Ejemplo n.º 2
0
        public void AddAllFromOther()
        {
            ConstructorArgumentValues other = new ConstructorArgumentValues();

            other.AddIndexedArgumentValue(1, DBNull.Value);
            other.AddIndexedArgumentValue(2, "Foo");
            other.AddIndexedArgumentValue(3, 3);

            ConstructorArgumentValues values = new ConstructorArgumentValues();

            values.AddAll(other);
            Assert.AreEqual(other.ArgumentCount, values.ArgumentCount,
                            "Must have been the same since one was filled up with the values in the other.");
        }
Ejemplo n.º 3
0
        public void AddIndexedArgumentValue()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            values.AddIndexedArgumentValue(1, DBNull.Value);
            Assert.IsFalse(values.Empty, "Added one value, but the collection is sayin' it's empty.");
            Assert.AreEqual(1, values.ArgumentCount, "Added one value, but the collection ain't sayin' that it's got a single element in it.");
            Assert.AreEqual(1, values.IndexedArgumentValues.Count, "Added one indexed value, but the collection of indexed values ain't sayin' that it's got a single element in it.");
        }
Ejemplo n.º 4
0
        public void GetIndexedArgumentValue()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            Assert.IsNull(values.GetIndexedArgumentValue(0, typeof(object)), "Mmm... managed to get a non null instance back from an empty instance.");
            values.AddIndexedArgumentValue(16, DBNull.Value, typeof(DBNull).FullName);
            Assert.IsNull(values.GetIndexedArgumentValue(0, typeof(object)), "Mmm... managed to get a non null instance back from an instance that should have now't at the specified index.");
            ConstructorArgumentValues.ValueHolder value =
                values.GetIndexedArgumentValue(16, typeof(DBNull));
            Assert.IsNotNull(value, "Stored a value at a specified index, but got null when retrieving it.");
            Assert.AreSame(DBNull.Value, value.Value, "The value stored at the specified index was not the exact same instance as was added.");
            ConstructorArgumentValues.ValueHolder wrongValue =
                values.GetIndexedArgumentValue(16, typeof(string));
            Assert.IsNull(wrongValue, "Stored a value at a specified index, and got it (or rather something) back when retrieving it with the wrong Type specified.");
        }
Ejemplo n.º 5
0
        public void GetArgumentValue()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            Assert.IsNull(values.GetArgumentValue(0, typeof(object)), "Mmm... managed to get a non null instance back from an empty instance.");
            values.AddGenericArgumentValue(DBNull.Value, typeof(DBNull).FullName);
            values.AddNamedArgumentValue("foo", DBNull.Value);
            values.AddIndexedArgumentValue(16, DBNull.Value, typeof(DBNull).FullName);
            Assert.IsNull(values.GetArgumentValue(100, typeof(string)), "Mmm... managed to get a non null instance back from an instance that should have now't with the specified Type.");
            ConstructorArgumentValues.ValueHolder value =
                values.GetArgumentValue(-3, typeof(DBNull));
            Assert.IsNotNull(value, "Stored a value of a specified Type at a specified index, but got null when retrieving it using the wrong index but the correct Type.");
            Assert.AreSame(DBNull.Value, value.Value, "The retrieved value was not the exact same instance as was added.");

            value = values.GetArgumentValue("foo", typeof(DBNull));
            Assert.IsNotNull(value, "Stored a value of a specified Type under a name, but got null when retrieving it using the wrong name but the correct Type.");
            Assert.AreSame(DBNull.Value, value.Value, "The retrieved value was not the exact same instance as was added.");
        }
Ejemplo n.º 6
0
        public void GetArgumentValueIgnoresAlreadyUsedValues()
        {
            ISet used = new ListSet();

            ConstructorArgumentValues values = new ConstructorArgumentValues();

            values.AddGenericArgumentValue(1);
            values.AddNamedArgumentValue("2", 2);
            values.AddIndexedArgumentValue(3, 3);

            Type intType = typeof(int);

            ConstructorArgumentValues.ValueHolder one = values.GetArgumentValue(10, string.Empty, intType, used);
            Assert.AreEqual(1, one.Value);
            used.Add(one);
            ConstructorArgumentValues.ValueHolder two = values.GetArgumentValue(10, "2", intType, used);
            Assert.AreEqual(2, two.Value);
            used.Add(two);
            ConstructorArgumentValues.ValueHolder three = values.GetArgumentValue(3, string.Empty, intType, used);
            Assert.AreEqual(3, three.Value);
            used.Add(three);
            ConstructorArgumentValues.ValueHolder four = values.GetArgumentValue(10, string.Empty, intType, used);
            Assert.IsNull(four);
        }
        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);
        }