コード例 #1
0
        public void Create_a_default_instance()
        {
            MemoryInstanceMemento memento = MemoryInstanceMemento.CreateDefaultInstanceMemento();
            Instance instance             = memento.ReadInstance(null, null);

            Assert.IsInstanceOfType(typeof(DefaultInstance), instance);
        }
コード例 #2
0
        public void Create_a_default_instance()
        {
            MemoryInstanceMemento memento = MemoryInstanceMemento.CreateDefaultInstanceMemento();
            Instance instance             = memento.ReadInstance(null, GetType());

            instance.ShouldBeOfType <DefaultInstance>();
        }
コード例 #3
0
        public void Create_a_referenced_instance()
        {
            MemoryInstanceMemento memento = MemoryInstanceMemento.CreateReferencedInstanceMemento("blue");
            var instance = (ReferencedInstance)memento.ReadInstance(null, null);

            Assert.AreEqual("blue", instance.ReferenceKey);
        }
コード例 #4
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");
        }
コード例 #5
0
        public void add_instance_memento_negative_should_log_error()
        {
            var memento = new MemoryInstanceMemento(typeof (TargetXmlWithCtor).AssemblyQualifiedName, "mine");
            reader.ForMemento(memento, (r, i) => {Assert.Fail("Should not be called");});

            log.ErrorCount.ShouldBeGreaterThan(0);
        }
コード例 #6
0
ファイル: MementoTester.cs プロジェクト: hp4711/structuremap
        public void If_a_Memento_does_not_know_its_PluggedType_or_concreteKey_select_the_DEFAULT_Plugin()
        {
            var family = new PluginFamily(typeof (IGateway));
            Plugin plugin = family.AddPlugin(typeof (TheGateway), Plugin.DEFAULT);

            var memento = new MemoryInstanceMemento();
            Assert.AreSame(plugin, memento.FindPlugin(family));
        }
コード例 #7
0
        public void Do_not_try_to_execute_the_action_when_requested_system_object_if_it_cannot_be_created()
        {
            var memento = new MemoryInstanceMemento();
            var builder = new GraphBuilder(new Registry[0]);

            builder.WithSystemObject <MementoSource>(memento, "I am going to break here",
                                                     delegate { Assert.Fail("Wasn't supposed to be called"); });
        }
コード例 #8
0
        public void Do_not_try_to_execute_the_action_when_requested_system_object_if_it_cannot_be_created()
        {
            var memento = new MemoryInstanceMemento();
            var builder = new GraphBuilder(new Registry[0]);

            builder.WithSystemObject<MementoSource>(memento, "I am going to break here",
                                                    delegate { Assert.Fail("Wasn't supposed to be called"); });
        }
コード例 #9
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);
        }
コード例 #10
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 CanRenameInstanceMemento()
        {
            var memento = new MemoryInstanceMemento("concrete", "name");

            Assert.AreEqual("name", memento.InstanceKey);
            memento.InstanceKey = "Elvis";

            Assert.AreEqual("Elvis", memento.InstanceKey);
        }
コード例 #12
0
        public void Log_an_error_for_a_requested_system_object_if_it_cannot_be_created()
        {
            var memento = new MemoryInstanceMemento();
            var builder = new GraphBuilder(new Registry[0]);

            builder.WithSystemObject <MementoSource>(memento, "I am going to break here", delegate { });

            builder.PluginGraph.Log.AssertHasError(130);
        }
        public void CanRenameInstanceMemento()
        {
            var memento = new MemoryInstanceMemento("concrete", "name");

            Assert.AreEqual("name", memento.InstanceKey);
            memento.InstanceKey = "Elvis";

            Assert.AreEqual("Elvis", memento.InstanceKey);
        }
コード例 #14
0
        public void If_a_Memento_does_not_know_its_PluggedType_or_concreteKey_select_the_DEFAULT_Plugin()
        {
            var    family = new PluginFamily(typeof(IGateway));
            Plugin plugin = family.AddPlugin(typeof(TheGateway), Plugin.DEFAULT);

            var memento = new MemoryInstanceMemento();

            Assert.AreSame(plugin, memento.FindPlugin(family));
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
        public void SetUp()
        {
            Type pluggedType = typeof (StubbedGateway);

            var values = new NameValueCollection();
            values.Add(XmlConstants.PLUGGED_TYPE, pluggedType.AssemblyQualifiedName);
            _memento = new MemoryInstanceMemento(string.Empty, "Frank", values);

            _expectedPlugin = new Plugin(pluggedType);
        }
        public void SetUp()
        {
            Type pluggedType = typeof(StubbedGateway);

            var values = new NameValueCollection();

            values.Add(XmlConstants.PLUGGED_TYPE, pluggedType.AssemblyQualifiedName);
            _memento = new MemoryInstanceMemento(string.Empty, "Frank", values);

            _expectedPlugin = new Plugin(pluggedType);
        }
コード例 #19
0
        public void add_instance_memento_all_positive_from_alias()
        {
            reader.AliasType("a", typeof(AWidget).AssemblyQualifiedName);
            var memento = new MemoryInstanceMemento("a", "mine");
            reader.ForMemento(memento, (r, i) => r.For<IWidget>().Add(i));

            assertThatThereAreNotErrorsDetected();

            var container = new Container(registry);

            container.GetInstance<IWidget>("mine").ShouldBeOfType<AWidget>();
        }
コード例 #20
0
        public void ReadChildProperty_child_property_is_defined_build_child()
        {
            var memento = ComplexRule.GetMemento();

            memento.SetPluggedType <ComplexRule>();
            MemoryInstanceMemento carMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento("GrandPrix");

            memento.AddChild("car", carMemento);

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

            Assert.AreEqual("GrandPrix", child.ReferenceKey);
        }
コード例 #21
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);
            }
コード例 #22
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"));
        }
コード例 #23
0
        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);
        }
コード例 #24
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);
        }
コード例 #25
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"));
        }
コード例 #26
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);
        }
コード例 #27
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);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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");
        }
コード例 #30
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"));
        }
コード例 #31
0
        public void Log_an_error_for_a_requested_system_object_if_it_cannot_be_created()
        {
            var memento = new MemoryInstanceMemento();
            var builder = new GraphBuilder(new Registry[0]);

            builder.WithSystemObject<MementoSource>(memento, "I am going to break here", delegate { });

            builder.PluginGraph.Log.AssertHasError(130);
        }
コード例 #32
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;
            }