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); }