コード例 #1
0
        public void Read_a_string_string_dictionary2()
        {
            string xml =
                @"
<node>
    <Pair Key='color' Value='red'/>
    <Pair Key='state' Value='texas'/>
    <Pair Key='direction' Value='north'/>
</node>
";

            Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement,
                                                            typeof(Dictionary <string, string>));

            //instance.ShouldBeOfType(typeof (SerializedInstance));

            Assert.Fail("NWO");

//            var collection =
//                (Dictionary<string, string>) instance.Build(typeof (Dictionary<string, string>), new StubBuildSession());
//
//            collection["color"].ShouldEqual("red");
//            collection["state"].ShouldEqual("texas");
//            collection["direction"].ShouldEqual("north");
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        public void Read_an_int_string_dictionary()
        {
            string xml =
                @"
<node>
    <Pair Key='1' Value='red'/>
    <Pair Key='2' Value='texas'/>
    <Pair Key='3' Value='north'/>
</node>
";

            Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement,
                                                            typeof(IDictionary <int, string>));

            //instance.ShouldBeOfType(typeof (SerializedInstance));

            Assert.Fail("NWO");

//            var collection =
//                (IDictionary<int, string>) instance.Build(typeof (IDictionary<int, string>), new StubBuildSession());
//
//            collection[1].ShouldEqual("red");
//            collection[2].ShouldEqual("texas");
//            collection[3].ShouldEqual("north");
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        private object parseNode(string xml, Type pluginType)
        {
            XmlElement element  = DataMother.BuildDocument(xml).DocumentElement;
            var        reader   = new PrimitiveArrayReader();
            Instance   instance = reader.Read(element, pluginType);

            return(instance.Build(pluginType, new StubBuildSession()));
        }
コード例 #6
0
        private object parseNode(string xml, Type pluginType)
        {
            XmlElement element  = DataMother.BuildDocument(xml).DocumentElement;
            var        reader   = new PrimitiveArrayReader();
            Instance   instance = reader.Read(element, pluginType);

            throw new NotImplementedException("Redo for the NWO");
            //return instance.Build(pluginType, new StubBuildSession());
        }
コード例 #7
0
        public void Read_an_instance_for_NameValueCollection()
        {
            string xml =
                @"
<node>
    <Pair Key='color' Value='red'/>
    <Pair Key='state' Value='texas'/>
    <Pair Key='direction' Value='north'/>
</node>
";

            Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement,
                                                            typeof(NameValueCollection));

            instance.ShouldBeOfType(typeof(SerializedInstance));

            var collection = (NameValueCollection)instance.Build(typeof(NameValueCollection), new StubBuildSession());

            collection["color"].ShouldEqual("red");
            collection["state"].ShouldEqual("texas");
            collection["direction"].ShouldEqual("north");
        }
コード例 #8
0
        public void Read_a_string_int_dictionary2()
        {
            string xml =
                @"
<node>
    <Pair Key='color' Value='1'/>
    <Pair Key='state' Value='2'/>
    <Pair Key='direction' Value='3'/>
</node>
";

            Instance instance = new DictionaryReader().Read(DataMother.BuildDocument(xml).DocumentElement,
                                                            typeof(Dictionary <string, int>));

            instance.ShouldBeOfType(typeof(SerializedInstance));

            var collection =
                (Dictionary <string, int>)instance.Build(typeof(Dictionary <string, int>), new StubBuildSession());

            collection["color"].ShouldEqual(1);
            collection["state"].ShouldEqual(2);
            collection["direction"].ShouldEqual(3);
        }