public void CanApplyConstructorArgsToAbstractType()
        {
            IResource resource = new ReadOnlyXmlTestResource("ctor-args.xml", GetType());
            XmlObjectFactory xof = new XmlObjectFactory(resource);
            TestObject rod = (TestObject)xof.GetObject("rod");
            Assert.AreEqual(1, rod.Age);

            RootObjectDefinition def = (RootObjectDefinition) xof.GetObjectDefinition("rod");
            ConstructorResolver resolver = new ConstructorResolver(xof, xof, new SimpleInstantiationStrategy(), 
                                                    new ObjectDefinitionValueResolver(xof));
            
            ConstructorInstantiationInfo ci = resolver.GetConstructorInstantiationInfo("rod", def, null, null);

            AbstractObjectDefinition objDef = (AbstractObjectDefinition)xof.GetObjectDefinition("foo");
            objDef.IsAbstract = false;

            TestObject foo = (TestObject) xof.GetObject("foo");


            Assert.AreEqual(2, foo.Age);
        }
Beispiel #2
0
        public void CanApplyConstructorArgsToAbstractType()
        {
            IResource        resource = new ReadOnlyXmlTestResource("ctor-args.xml", GetType());
            XmlObjectFactory xof      = new XmlObjectFactory(resource);
            TestObject       rod      = (TestObject)xof.GetObject("rod");

            Assert.AreEqual(1, rod.Age);

            RootObjectDefinition def      = (RootObjectDefinition)xof.GetObjectDefinition("rod");
            ConstructorResolver  resolver = new ConstructorResolver(xof, xof, new SimpleInstantiationStrategy(),
                                                                    new ObjectDefinitionValueResolver(xof));

            ConstructorInstantiationInfo ci = resolver.GetConstructorInstantiationInfo("rod", def, null, null);

            AbstractObjectDefinition objDef = (AbstractObjectDefinition)xof.GetObjectDefinition("foo");

            objDef.IsAbstract = false;

            TestObject foo = (TestObject)xof.GetObject("foo");


            Assert.AreEqual(2, foo.Age);
        }
        public void ReadsMongoAttributesCorrectly()
        {
            string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
                           <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>
                                <mongo:mongo url='mongodb://localhost' write-concern='WMajority' />
                           </objects>";
            var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));

            Assert.That(factory.GetObjectDefinitionNames(), Contains.Item("Mongo"));

            IObjectDefinition definition = factory.GetObjectDefinition("Mongo");

            Assert.That(definition, Is.Not.Null);

            IList<PropertyValue> values = definition.PropertyValues.PropertyValues;

            Assert.That(values, Contains.Item(new PropertyValue("WriteConcern", "WMajority")));
            Assert.That(values, Contains.Item(new PropertyValue("Url", "mongodb://localhost")));
        }
        private void _TypedStringValueIsPickedUp(out Stream stream)
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
	xsi:schemaLocation='http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd'>
	<object id='golyadkin' type='Spring.Objects.TestObject, Spring.Core.Tests'>
		<property name='Hats'><value type='string[]'>trilby,fedora</value></property>
	</object>
</objects>";
            stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
            XmlObjectFactory fac = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
            IObjectDefinition def = fac.GetObjectDefinition("golyadkin");
            PropertyValue value = def.PropertyValues.GetPropertyValue("Hats");
            Assert.AreEqual(typeof(TypedStringValue), value.Value.GetType());
            TestObject obj = (TestObject) fac.GetObject("golyadkin");
            Assert.IsTrue(ArrayUtils.AreEqual(new string[] {"trilby", "fedora"}, obj.Hats));
        }
 public void ParsesNamedCtorArgsCorrectly()
 {
     XmlObjectFactory fac = new XmlObjectFactory(
         new ReadOnlyXmlTestResource("constructor-arg.xml", GetType()));
     IObjectDefinition obj = fac.GetObjectDefinition("ctorArgsAllNamed");
     Assert.AreEqual(2, obj.ConstructorArgumentValues.NamedArgumentValues.Count,
                     "Should have parsed 2 named ctor args.");
     ConstructorArgumentValues.ValueHolder nameArg = obj.ConstructorArgumentValues.GetNamedArgumentValue("name");
     Assert.IsNotNull(nameArg, "Should have parsed the 'name' ctor arg.");
     Assert.AreEqual("Isaac Newton", nameArg.Value);
     ConstructorArgumentValues.ValueHolder ageArg = obj.ConstructorArgumentValues.GetNamedArgumentValue("age");
     Assert.IsNotNull(ageArg, "Should have parsed the 'age' ctor arg.");
     Assert.AreEqual("87", ageArg.Value);
 }
        public void SetsUpMongoDbFactoryUsingAMongoConnectStringWithoutCredentials()
        {
            string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
                           <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>
                             <mongo:db-factory url='mongodb://localhost/database' />
                           </objects>";
            var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));

            IObjectDefinition definition = factory.GetObjectDefinition("MongoDatabaseFactory");
            ConstructorArgumentValues constructorArguments = definition.ConstructorArgumentValues;

            Assert.That(constructorArguments.ArgumentCount, Is.EqualTo(1));

            var argument = constructorArguments.GetArgumentValue(0, typeof(MongoUrl));

            Assert.That(argument, Is.Not.Null);

            var dbFactory = factory.GetObject<IMongoDatabaseFactory>("MongoDatabaseFactory");
            var db = dbFactory.GetDatabase();

            Assert.That(db.Name, Is.EqualTo("database"));
        }