public void ChokesOnCircularReferenceToPlaceHolder()
        {
            RootObjectDefinition def = new RootObjectDefinition();

            def.ObjectType = typeof(TestObject);
            ConstructorArgumentValues args = new ConstructorArgumentValues();

            args.AddNamedArgumentValue("name", "${foo}");
            def.ConstructorArgumentValues = args;

            NameValueCollection properties   = new NameValueCollection();
            const string        expectedName = "ba${foo}r";

            properties.Add("foo", expectedName);

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

            Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string[] { "foo" });
            Expect.Call(mock.GetObjectDefinition(null, false)).IgnoreArguments().Return(def);
            mocks.ReplayAll();

            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();

            cfg.Properties = properties;
            try
            {
                cfg.PostProcessObjectFactory(mock);
                Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point.");
            }
            catch (ObjectDefinitionStoreException)
            {
            }
            mocks.VerifyAll();
        }
        public void UsingCustomMarkers()
        {
            RootObjectDefinition def = new RootObjectDefinition();

            def.ObjectType = typeof(TestObject);
            ConstructorArgumentValues args = new ConstructorArgumentValues();

            args.AddNamedArgumentValue("name", "#hope.floats#");
            def.ConstructorArgumentValues = args;

            NameValueCollection properties   = new NameValueCollection();
            const string        expectedName = "Rick";

            properties.Add("hope.floats", expectedName);

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

            Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string[] { "foo" });
            Expect.Call(mock.GetObjectDefinition(null, false)).IgnoreArguments().Return(def);
            Expect.Call(() => mock.AddEmbeddedValueResolver(null)).IgnoreArguments();
            mocks.ReplayAll();

            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();

            cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#";
            cfg.Properties        = properties;
            cfg.PostProcessObjectFactory(mock);

            mocks.VerifyAll();

            Assert.AreEqual(expectedName,
                            def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value,
                            "Named argument placeholder value was not replaced.");
        }
示例#3
0
        public void AddNamedArgument()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            values.AddNamedArgumentValue("foo", "sball");
            Assert.AreEqual(1, values.NamedArgumentValues.Count, "Added one named argument but it doesn't seem to have been added to the named arguments collection.");
            Assert.AreEqual(1, values.ArgumentCount, "Added one named argument but it doesn't seem to be reflected in the overall argument count.");
            ConstructorArgumentValues.ValueHolder arg = values.GetNamedArgumentValue("foo");
            Assert.IsNotNull(arg, "The named argument previously added could not be pulled from the ctor arg collection.");
            Assert.AreEqual("sball", arg.Value, "The value of the named argument passed in is not the same as the one that was pulled out.");
        }
示例#4
0
        public void NamedArgumentsAreCaseInsensitive()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            values.AddNamedArgumentValue("foo", "sball");
            Assert.AreEqual(1, values.NamedArgumentValues.Count, "Added one named argument but it doesn't seem to have been added to the named arguments collection.");
            Assert.AreEqual(1, values.ArgumentCount, "Added one named argument but it doesn't seem to be reflected in the overall argument count.");
            Assert.IsTrue(values.ContainsNamedArgument("FOo"), "Mmm, the ContainsNamedArgument() method eveidently IS case sensitive (which is wrong).");
            ConstructorArgumentValues.ValueHolder arg = values.GetNamedArgumentValue("fOo");
            Assert.IsNotNull(arg, "The named argument previously added could not be pulled from the ctor arg collection.");
            Assert.AreEqual("sball", arg.Value, "The value of the named argument passed in is not the same as the one that was pulled out.");
        }
示例#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.");
        }
示例#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);
        }
示例#7
0
        public void AddNamedArgumentWithWhitespaceStringName()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            Assert.Throws <ArgumentNullException>(() => values.AddNamedArgumentValue(Environment.NewLine + "  ", 1));
        }
示例#8
0
        public void AddNamedArgumentWithEmptyStringName()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            Assert.Throws <ArgumentNullException>(() => values.AddNamedArgumentValue(string.Empty, 1));
        }
示例#9
0
        public void AddNamedArgumentWithNullName()
        {
            ConstructorArgumentValues values = new ConstructorArgumentValues();

            Assert.Throws <ArgumentNullException>(() => values.AddNamedArgumentValue(null, 1));
        }