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);
        }
        public void GetLargeStringInAttributeMemento()
        {
            XmlDocument document = DataMother.GetXmlDocument("CDataTest.xml");
            XmlNode     node     = document.DocumentElement.LastChild;

            var memento = new XmlAttributeInstanceMemento(node);

            Assert.AreEqual("select * from table", memento.GetProperty("bigProp"));
        }
예제 #4
0
        private void attachMementoSource(PluginFamily family, XmlElement familyElement)
        {
            familyElement.IfHasNode(MEMENTO_SOURCE_NODE).Do(node =>
            {
                InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(node);

                string context = string.Format("MementoSource for {0}\n{1}",
                                               family.PluginType.AssemblyQualifiedName, node.OuterXml);
                _builder.WithSystemObject <MementoSource>(sourceMemento, context,
                                                          source => family.AddMementoSource(source));
            });
        }
예제 #5
0
        private void attachInterceptors(PluginFamily family, XmlElement familyElement)
        {
            string contextBase = string.Format("creating an InstanceInterceptor for {0}\n",
                                               family.PluginType.AssemblyQualifiedName);

            familyElement.ForEachChild("*/Interceptor").Do(element =>
            {
                var interceptorMemento = new XmlAttributeInstanceMemento(element);
                string context         = contextBase + element.OuterXml;


                _builder.WithSystemObject <ILifecycle>(
                    interceptorMemento,
                    context,
                    lifecycle => family.SetScopeTo(lifecycle));
            });
        }