public void RefSubelementsBuildCollectionFromSingleElement() { IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType()); XmlObjectFactory xof = new XmlObjectFactory(resource); TestObject loner = (TestObject)xof.GetObject("loner"); TestObject dave = (TestObject)xof.GetObject("david"); Assert.IsTrue(loner.Friends.Count == 1); bool contains = false; foreach (object friend in loner.Friends) { if (friend == dave) { contains = true; break; } } Assert.IsTrue(contains); }
public void MapWithLiteralsAndPrototypeReferences() { IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType()); XmlObjectFactory xof = new XmlObjectFactory(resource); TestObject jenny = (TestObject)xof.GetObject("pJenny"); HasMap hasMap = (HasMap)xof.GetObject("pMixedMap"); Assert.IsTrue(hasMap.Map.Count == 2); Assert.IsTrue(hasMap.Map["foo"].Equals("bar")); Assert.IsTrue(hasMap.Map["jenny"].ToString().Equals(jenny.ToString())); Assert.IsTrue(hasMap.Map["jenny"] != jenny, "Not same instance"); HasMap hasMap2 = (HasMap)xof.GetObject("pMixedMap"); Assert.IsTrue(hasMap2.Map.Count == 2); Assert.IsTrue(hasMap2.Map["foo"].Equals("bar")); Assert.IsTrue(hasMap2.Map["jenny"].ToString().Equals(jenny.ToString())); Assert.IsTrue(hasMap2.Map["jenny"] != hasMap.Map["jenny"], "Not same instance"); }
public void LocaleTest() { CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); IResource resource = new ReadOnlyXmlTestResource("locale.xml", GetType()); XmlObjectFactory xof = new XmlObjectFactory(resource); TestObject to = xof.GetObject("jenny") as TestObject; Assert.IsNotNull(to); DateTime d = new DateTime(2007, 10, 30); Assert.AreEqual(d, to.Date); Assert.AreEqual(30, to.Size.Height); Assert.AreEqual(30, to.Size.Width); } finally { Thread.CurrentThread.CurrentCulture = oldCulture; } }
public void GetDictionaryWithValueRefAttributeShortcuts() { XmlObjectFactory xof = new XmlObjectFactory( new ReadOnlyXmlTestResource("collections.xml", GetType())); IDictionary map = (IDictionary)xof.GetObject("mapWithValueRefAttributeShortcuts"); Assert.AreEqual(2, map.Count); foreach (string key in map.Keys) { object obj = map[key]; Assert.IsNotNull(obj); Assert.AreEqual(typeof(TestObject), obj.GetType(), "Wrong value assigned to value of dictionary."); TestObject tob = (TestObject)obj; if (key == "rick") { Assert.AreEqual("Rick Evans", tob.Name, "Wrong object value assigned to the 'rick' key."); } else if (key == "uncleelvis") { Assert.AreEqual("Uncle Elvis", tob.Name, "Wrong object value assigned to the 'uncleelvis' key."); } } }
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); }