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");
        }
Exemplo n.º 2
0
        public void Create_a_referenced_instance()
        {
            MemoryInstanceMemento memento = MemoryInstanceMemento.CreateReferencedInstanceMemento("blue");
            var instance = (ReferencedInstance)memento.ReadInstance(null, null);

            Assert.AreEqual("blue", instance.ReferenceKey);
        }
Exemplo n.º 3
0
        public void Create_a_default_instance()
        {
            MemoryInstanceMemento memento = MemoryInstanceMemento.CreateDefaultInstanceMemento();
            Instance instance             = memento.ReadInstance(null, null);

            Assert.IsInstanceOfType(typeof(DefaultInstance), instance);
        }
        public void Create_a_default_instance()
        {
            MemoryInstanceMemento memento = MemoryInstanceMemento.CreateDefaultInstanceMemento();
            Instance instance             = memento.ReadInstance(null, GetType());

            instance.ShouldBeOfType <DefaultInstance>();
        }
        public void Get_the_instance_name()
        {
            var memento = new MemoryInstanceMemento("Color", "Red");
            memento.SetProperty("Color", "Red");
            memento.InstanceKey = "Red";

            Assert.AreEqual("Red", memento.ReadInstance(_graph, typeof (IService)).Name);
        }
        public void Get_the_instance_name()
        {
            var memento = new MemoryInstanceMemento("Color", "Red");
            memento.SetPluggedType<ColorService>();
            memento.SetProperty("Color", "Red");
            memento.InstanceKey = "Red";

            Assert.AreEqual("Red", memento.ReadInstance(new SimplePluginFactory(), typeof(IService)).Name);
        }
Exemplo n.º 7
0
        public void Get_the_instance_name()
        {
            var memento = new MemoryInstanceMemento("Color", "Red");

            memento.SetProperty("Color", "Red");
            memento.InstanceKey = "Red";

            Assert.AreEqual("Red", memento.ReadInstance(_graph, typeof(IService)).Name);
        }
        public void Get_the_instance_name()
        {
            var memento = new MemoryInstanceMemento("Color", "Red");

            memento.SetPluggedType <ColorService>();
            memento.SetProperty("Color", "Red");
            memento.InstanceKey = "Red";

            Assert.AreEqual("Red", memento.ReadInstance(new SimplePluginFactory(), typeof(IService)).Name);
        }
Exemplo n.º 9
0
        public void ReadChildProperty_child_property_is_defined_build_child()
        {
            var graph = new PluginGraph();

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

            MemoryInstanceMemento memento = ComplexRule.GetMemento();

            memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof(ComplexRule).AssemblyQualifiedName);
            MemoryInstanceMemento carMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento("GrandPrix");

            memento.AddChild("car", carMemento);

            var instance = (IStructuredInstance)memento.ReadInstance(graph, typeof(Rule));
            var child    = (ReferencedInstance)instance.GetChild("car");

            Assert.AreEqual("GrandPrix", child.ReferenceKey);
        }
Exemplo n.º 10
0
        public void ReadPrimitivePropertiesHappyPath()
        {
            var graph = new PluginGraph();

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

            MemoryInstanceMemento memento = ComplexRule.GetMemento();

            memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof(ComplexRule).AssemblyQualifiedName);

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


            Assert.AreEqual(memento.GetProperty("String"), instance.GetProperty("String"));
            Assert.AreEqual(memento.GetProperty("Breed"), instance.GetProperty("Breed"));
            Assert.AreEqual(memento.GetProperty("Int"), instance.GetProperty("Int"));
            Assert.AreEqual(memento.GetProperty("Long"), instance.GetProperty("Long"));
            Assert.AreEqual(memento.GetProperty("Byte"), instance.GetProperty("Byte"));
            Assert.AreEqual(memento.GetProperty("Double"), instance.GetProperty("Double"));
            Assert.AreEqual(memento.GetProperty("Bool"), instance.GetProperty("Bool"));
        }
        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");
        }