Beispiel #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 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 Create_system_object_successfully_and_call_the_requested_action()
        {
            var memento = new MemoryInstanceMemento("XmlFile", "anything");
            memento.SetProperty("FilePath", "something");
            memento.SetProperty("XPath", "nodeName");
            memento.SetProperty("NodeName", "something");

            bool iWasCalled = false;

            var builder = new GraphBuilder(new Registry[0]);
            builder.WithSystemObject<MementoSource>(memento, "some xml", policy =>
            {
                Assert.IsInstanceOfType(typeof (XmlFileMementoSource), policy);
                iWasCalled = true;
            });

            Assert.IsTrue(iWasCalled);
        }
        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);
        }
Beispiel #5
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 MakeSubstitutionsInXmlNode()
        {
            var memento = new MemoryInstanceMemento("", "");
            memento.SetProperty("color", "blue");
            memento.SetProperty("name", "ObiWan");
            memento.SetProperty("state", "New York");
            memento.SetProperty("direction", "North");

            XmlNode templateNode = _document.DocumentElement.FirstChild;
            var templater = new XmlTemplater(templateNode);

            XmlNode expectedNode = _document.DocumentElement.LastChild;
            var checker = new ElementChecker((XmlElement) expectedNode);

            var actualElement = (XmlElement) templater.SubstituteTemplates(templateNode, memento);

            Assert.IsFalse(ReferenceEquals(templateNode, actualElement));
            checker.Check(actualElement);
        }
        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);
        }
Beispiel #8
0
        public void MakeSubstitutionsInXmlNode()
        {
            var memento = new MemoryInstanceMemento("", "");

            memento.SetProperty("color", "blue");
            memento.SetProperty("name", "ObiWan");
            memento.SetProperty("state", "New York");
            memento.SetProperty("direction", "North");

            XmlNode templateNode = _document.DocumentElement.FirstChild;
            var     templater    = new XmlTemplater(templateNode);

            XmlNode expectedNode = _document.DocumentElement.LastChild;
            var     checker      = new ElementChecker((XmlElement)expectedNode);

            var actualElement = (XmlElement)templater.SubstituteTemplates(templateNode, memento);

            Assert.IsFalse(ReferenceEquals(templateNode, actualElement));
            checker.Check(actualElement);
        }
        public void Create_system_object_successfully_and_call_the_requested_action()
        {
            var memento = new MemoryInstanceMemento("XmlFile", "anything");

            memento.SetProperty("FilePath", "something");
            memento.SetProperty("XPath", "nodeName");
            memento.SetProperty("NodeName", "something");


            bool iWasCalled = false;

            var builder = new GraphBuilder(new Registry[0]);

            builder.WithSystemObject <MementoSource>(memento, "some xml", policy =>
            {
                Assert.IsInstanceOfType(typeof(XmlFileMementoSource), policy);
                iWasCalled = true;
            });

            Assert.IsTrue(iWasCalled);
        }
        public void HandleStringEmpty()
        {
            var memento = new MemoryInstanceMemento("", "");
            memento.SetProperty("color", "");

            var doc = new XmlDocument();
            XmlElement element = doc.CreateElement("top");
            doc.AppendChild(element);
            element.SetAttribute("Color", "{color}");

            var templater = new XmlTemplater(element);

            var result = (XmlElement) templater.SubstituteTemplates(element, memento);
            Assert.AreEqual(InstanceMemento.EMPTY_STRING, result.GetAttribute("Color"));
        }
Beispiel #11
0
            public static MemoryInstanceMemento GetMemento()
            {
                var memento = new MemoryInstanceMemento("", "Sample");

                memento.SetProperty("String", "Red");
                memento.SetProperty("Breed", "Longhorn");
                memento.SetProperty("Int", "1");
                memento.SetProperty("Long", "2");
                memento.SetProperty("Byte", "3");
                memento.SetProperty("Double", "4");
                memento.SetProperty("Bool", "True");

                return(memento);
            }
Beispiel #12
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);
        }
Beispiel #13
0
        public void HandleStringEmpty()
        {
            var memento = new MemoryInstanceMemento("", "");

            memento.SetProperty("color", "");

            var        doc     = new XmlDocument();
            XmlElement element = doc.CreateElement("top");

            doc.AppendChild(element);
            element.SetAttribute("Color", "{color}");

            var templater = new XmlTemplater(element);

            var result = (XmlElement)templater.SubstituteTemplates(element, memento);

            Assert.AreEqual(InstanceMemento.EMPTY_STRING, result.GetAttribute("Color"));
        }
Beispiel #14
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 static MemoryInstanceMemento GetMemento()
            {
                var memento = new MemoryInstanceMemento("", "Sample");
                memento.SetProperty("String", "Red");
                memento.SetProperty("Breed", "Longhorn");
                memento.SetProperty("Int", "1");
                memento.SetProperty("Long", "2");
                memento.SetProperty("Byte", "3");
                memento.SetProperty("Double", "4");
                memento.SetProperty("Bool", "True");

                return memento;
            }