Example #1
0
        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")));
        }
Example #2
0
        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"));
        }