Exemplo n.º 1
0
        public void ReadChildArrayProperty()
        {
            var graph = new PluginGraph();

            graph.FindFamily(typeof(Rule)).AddPlugin(typeof(ComplexRule));

            MemoryInstanceMemento memento = ComplexRule.GetMemento();

            memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof(ComplexRule).AssemblyQualifiedName);
            memento.AddChildArray("cars", new InstanceMemento[]
            {
                MemoryInstanceMemento.CreateReferencedInstanceMemento("Ford"),
                MemoryInstanceMemento.CreateReferencedInstanceMemento("Chevy"),
                MemoryInstanceMemento.CreateReferencedInstanceMemento("Dodge"),
            });

            var instance = (IStructuredInstance)memento.ReadInstance(graph, typeof(Rule));

            Instance[] instances = instance.GetChildArray("cars");
            Assert.AreEqual(3, instances.Length);

            assertIsReference(instances[0], "Ford");
            assertIsReference(instances[1], "Chevy");
            assertIsReference(instances[2], "Dodge");
        }
        public void ReadChildArrayProperty()
        {
            MemoryInstanceMemento memento = ComplexRule.GetMemento();

            memento.SetPluggedType <ComplexRule>();
            memento.AddChildArray("cars", new InstanceMemento[]
            {
                MemoryInstanceMemento.CreateReferencedInstanceMemento("Ford"),
                MemoryInstanceMemento.CreateReferencedInstanceMemento("Chevy"),
                MemoryInstanceMemento.CreateReferencedInstanceMemento("Dodge"),
            });

            var instance = (IStructuredInstance)memento.ReadInstance(new SimplePluginFactory(), typeof(Rule));

            Instance[] instances = instance.GetChildArray("cars");
            Assert.AreEqual(3, instances.Length);

            assertIsReference(instances[0], "Ford");
            assertIsReference(instances[1], "Chevy");
            assertIsReference(instances[2], "Dodge");
        }