public void Read_in_a_dictionary_type_from_an_attribute_normalized_memento() { string xml = @" <root> <dictionary> <Pair Key='color' Value='red'/> <Pair Key='state' Value='texas'/> <Pair Key='direction' Value='north'/> </dictionary> </root> "; XmlElement element = DataMother.BuildDocument(xml).DocumentElement; element.SetAttribute("PluggedType", typeof(ClassWithDictionary).AssemblyQualifiedName); var memento = new XmlAttributeInstanceMemento(element); Instance instance = memento.ReadInstance(new SimplePluginFactory(), typeof(ClassWithDictionary)); var theObject = (ClassWithDictionary)instance.Build(typeof(ClassWithDictionary), BuildSession.Empty()); theObject.Dictionary["color"].ShouldEqual("red"); theObject.Dictionary["state"].ShouldEqual("texas"); theObject.Dictionary["direction"].ShouldEqual("north"); }
public void Read_in_a_class_with_primitive_arrays() { string xml = @" <Instance> <numbers Values='1,2,3'/> <strings Values='1,2,3'/> </Instance> "; XmlElement element = DataMother.BuildDocument(xml).DocumentElement; element.SetAttribute("PluggedType", typeof(ClassWithStringAndIntArray).AssemblyQualifiedName); var memento = new XmlAttributeInstanceMemento(element); var graph = new PluginGraph(); Instance instance = memento.ReadInstance(new SimplePluginFactory(), typeof(ClassWithStringAndIntArray)); var theObject = (ClassWithStringAndIntArray)instance.Build(typeof(ClassWithStringAndIntArray), BuildSession.ForPluginGraph(graph)); theObject.Numbers.ShouldEqual(new[] { 1, 2, 3 }); theObject.Strings.ShouldEqual(new[] { "1", "2", "3" }); Debug.WriteLine(theObject.GetType().AssemblyQualifiedName); }