public void AutoAliasing() { IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType()); XmlObjectFactory xof = new XmlObjectFactory(resource); IList <string> objectNames = xof.GetObjectDefinitionNames(); TestObject tb1 = (TestObject)xof.GetObject("aliased"); TestObject alias1 = (TestObject)xof.GetObject("myalias"); Assert.IsTrue(tb1 == alias1); IList <string> tb1Aliases = xof.GetAliases("aliased"); Assert.AreEqual(1, tb1Aliases.Count); Assert.IsTrue(tb1Aliases.Contains("myalias")); Assert.IsTrue(objectNames.Contains("aliased")); Assert.IsFalse(objectNames.Contains("myalias")); TestObject tb2 = (TestObject)xof.GetObject("multiAliased"); TestObject alias2 = (TestObject)xof.GetObject("alias1"); TestObject alias3 = (TestObject)xof.GetObject("alias2"); Assert.IsTrue(tb2 == alias2); Assert.IsTrue(tb2 == alias3); IList <string> tb2Aliases = xof.GetAliases("multiAliased"); Assert.AreEqual(2, tb2Aliases.Count); Assert.IsTrue(tb2Aliases.Contains("alias1")); Assert.IsTrue(tb2Aliases.Contains("alias2")); Assert.IsTrue(objectNames.Contains("multiAliased")); Assert.IsFalse(objectNames.Contains("alias1")); Assert.IsFalse(objectNames.Contains("alias2")); TestObject tb3 = (TestObject)xof.GetObject("aliasWithoutId1"); TestObject alias4 = (TestObject)xof.GetObject("aliasWithoutId2"); TestObject alias5 = (TestObject)xof.GetObject("aliasWithoutId3"); Assert.IsTrue(tb3 == alias4); Assert.IsTrue(tb3 == alias5); IList <string> tb3Aliases = xof.GetAliases("aliasWithoutId1"); Assert.AreEqual(2, tb2Aliases.Count); Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId2")); Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId3")); Assert.IsTrue(objectNames.Contains("aliasWithoutId1")); Assert.IsFalse(objectNames.Contains("aliasWithoutId2")); Assert.IsFalse(objectNames.Contains("aliasWithoutId3")); string className = typeof(TestObject).FullName; string targetName = className + ObjectDefinitionReaderUtils.GENERATED_OBJECT_NAME_SEPARATOR + "0"; TestObject tb4 = (TestObject)xof.GetObject(targetName); Assert.AreEqual(null, tb4.Name); }
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 _ChildDefinitionWithoutIdOrNameOrALiasGetsOneAutogenerated(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='mother' abstract='true' type='Spring.Objects.TestObject, Spring.Core.Tests'/> <object parent='mother'/> </objects>"; stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)); XmlObjectFactory factory = new XmlObjectFactory(new InputStreamResource(stream, string.Empty)); IList<string> names = factory.GetObjectDefinitionNames(); // mmm, how is one to test this? I have no idea what the generated name is... Assert.AreEqual(2, names.Count, "Should have got two object names, one of which is autogenerated."); }
public void IfNoIdUseDefault() { string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'> <mongo:convention-profile /> </objects>"; var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8)); Assert.That(factory.GetObjectDefinitionNames(), Contains.Item("MongoConventionProfile")); var conventionProfile = factory.GetObject("MongoConventionProfile") as ConventionProfile; Assert.That(conventionProfile, Is.Not.Null); Assert.That(conventionProfile.DefaultValueConvention, Is.TypeOf<NullDefaultValueConvention>()); Assert.That(conventionProfile.ElementNameConvention, Is.TypeOf<MemberNameElementNameConvention>()); Assert.That(conventionProfile.ExtraElementsMemberConvention, Is.TypeOf<NamedExtraElementsMemberConvention>()); Assert.That(conventionProfile.IdGeneratorConvention, Is.TypeOf<LookupIdGeneratorConvention>()); Assert.That(conventionProfile.IdMemberConvention, Is.TypeOf<NamedIdMemberConvention>()); Assert.That(conventionProfile.IgnoreExtraElementsConvention, Is.TypeOf<NeverIgnoreExtraElementsConvention>()); Assert.That(conventionProfile.IgnoreIfDefaultConvention, Is.TypeOf<NeverIgnoreIfDefaultConvention>()); Assert.That(conventionProfile.IgnoreIfNullConvention, Is.TypeOf<NeverIgnoreIfNullConvention>()); Assert.That(conventionProfile.MemberFinderConvention, Is.TypeOf<PublicMemberFinderConvention>()); Assert.That(conventionProfile.SerializationOptionsConvention, Is.TypeOf<NullSerializationOptionsConvention>()); }
public void ReadsReplicaSetCorrectly() { string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'> <mongo:mongo id='Mongo2' replica-set='127.0.0.1:4711,127.0.0.1:4712' /> </objects>"; var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8)); Assert.That(factory.GetObjectDefinitionNames(), Contains.Item("Mongo2")); var server = factory.GetObject<MongoServer>("Mongo2"); Assert.That(server, Is.Not.Null); Assert.That(server.Settings.Servers, Contains.Item(new MongoServerAddress("127.0.0.1", 4711))); Assert.That(server.Settings.Servers, Contains.Item(new MongoServerAddress("127.0.0.1", 4712))); }
public void AutoAliasing() { IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType()); XmlObjectFactory xof = new XmlObjectFactory(resource); IList<string> objectNames = xof.GetObjectDefinitionNames(); TestObject tb1 = (TestObject) xof.GetObject("aliased"); TestObject alias1 = (TestObject) xof.GetObject("myalias"); Assert.IsTrue(tb1 == alias1); IList<string> tb1Aliases = xof.GetAliases("aliased"); Assert.AreEqual(1, tb1Aliases.Count); Assert.IsTrue(tb1Aliases.Contains("myalias")); Assert.IsTrue(objectNames.Contains("aliased")); Assert.IsFalse(objectNames.Contains("myalias")); TestObject tb2 = (TestObject) xof.GetObject("multiAliased"); TestObject alias2 = (TestObject) xof.GetObject("alias1"); TestObject alias3 = (TestObject) xof.GetObject("alias2"); Assert.IsTrue(tb2 == alias2); Assert.IsTrue(tb2 == alias3); IList<string> tb2Aliases = xof.GetAliases("multiAliased"); Assert.AreEqual(2, tb2Aliases.Count); Assert.IsTrue(tb2Aliases.Contains("alias1")); Assert.IsTrue(tb2Aliases.Contains("alias2")); Assert.IsTrue(objectNames.Contains("multiAliased")); Assert.IsFalse(objectNames.Contains("alias1")); Assert.IsFalse(objectNames.Contains("alias2")); TestObject tb3 = (TestObject) xof.GetObject("aliasWithoutId1"); TestObject alias4 = (TestObject) xof.GetObject("aliasWithoutId2"); TestObject alias5 = (TestObject) xof.GetObject("aliasWithoutId3"); Assert.IsTrue(tb3 == alias4); Assert.IsTrue(tb3 == alias5); IList<string> tb3Aliases = xof.GetAliases("aliasWithoutId1"); Assert.AreEqual(2, tb2Aliases.Count); Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId2")); Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId3")); Assert.IsTrue(objectNames.Contains("aliasWithoutId1")); Assert.IsFalse(objectNames.Contains("aliasWithoutId2")); Assert.IsFalse(objectNames.Contains("aliasWithoutId3")); string className = typeof(TestObject).FullName; string targetName = className + ObjectDefinitionReaderUtils.GENERATED_OBJECT_NAME_SEPARATOR + "0"; TestObject tb4 = (TestObject)xof.GetObject(targetName); Assert.AreEqual(null, tb4.Name); }