コード例 #1
0
        public void GetNonTemplatedInstance()
        {
            InstanceMemento memento = _templatedSource.GetMemento("Nadine");

            Assert.AreEqual("80", memento.GetProperty("Age"));
            Assert.AreEqual("Blue", memento.GetProperty("EyeColor"));
        }
コード例 #2
0
        private void validateCombinedMemento(InstanceMemento combinedMemento)
        {
            Assert.AreEqual("70", combinedMemento.GetProperty("Age"));
            Assert.AreEqual("Green", combinedMemento.GetProperty("EyeColor"));

            InstanceMemento grandChildMemeto =
                combinedMemento.GetChildMemento("MyChild").GetChildMemento("MyGrandChild");

            Assert.AreEqual("1992", grandChildMemeto.GetProperty("BirthYear"));
        }
        public void FetchOneMemento()
        {
            InstanceMemento memento = _source.GetMemento("Instance1");

            Assert.AreEqual("red", memento.GetProperty("color"));
            Assert.AreEqual("Instance1", memento.InstanceKey);
        }
コード例 #4
0
        public void GetRedInstance()
        {
            InstanceMemento memento = _source.GetMemento("Red");

            Assert.IsNotNull(memento);
            Assert.AreEqual("Red", memento.GetProperty("Color"));
        }
        public void FetchMachineNotFound()
        {
            source.SetMachineName("fake-machine");
            InstanceMemento memento = source.GetMemento("FavoriteColor");

            Assertion.AssertNotNull(memento);
            Assertion.AssertEquals("Default's favorite color is red", "Orange", memento.GetProperty("Color"));
        }
        public void Fetch1()
        {
            source.SetMachineName("server");
            InstanceMemento memento = source.GetMemento("FavoriteColor");

            Assertion.AssertNotNull(memento);
            Assertion.AssertEquals("Server's favorite color is blue", "Blue", memento.GetProperty("Color"));
        }
        public void Fetch2()
        {
            source.SetMachineName("localhost");
            InstanceMemento memento = source.GetMemento("FavoriteColor");

            Assertion.AssertNotNull(memento);
            Assertion.AssertEquals("Localhost's favorite color is red", "Red", memento.GetProperty("Color"));
        }
コード例 #8
0
        public void GetChildMemento()
        {
            InstanceMemento child = memento.GetChildMemento("Child1");

            Assert.IsNotNull(child);

            Assert.AreEqual("Child1", child.ConcreteKey, "Type is Child1");
            Assert.AreEqual("D", child.GetProperty("Prop4"), "Prop4");
        }
コード例 #9
0
        private void copyPrimitive(string name, bool isMandatory)
        {
            string propertyValue = _memento.GetProperty(name);

            if (propertyValue == null && isMandatory)
            {
                throw new StructureMapException(205, name, _memento.InstanceKey);
            }

            _instance.SetValue(name, propertyValue);
        }
コード例 #10
0
 public object BuildInstance(InstanceMemento Memento)
 {
     return new ComplexRule(
         Memento.GetProperty("String"),
         Memento.GetProperty("String2"),
         int.Parse(Memento.GetProperty("Int")),
         long.Parse(Memento.GetProperty("Long")),
         byte.Parse(Memento.GetProperty("Byte")),
         double.Parse(Memento.GetProperty("Double")),
         bool.Parse(Memento.GetProperty("Bool")));
 }
コード例 #11
0
 public object BuildInstance(InstanceMemento Memento)
 {
     return(new ComplexRule(
                Memento.GetProperty("String"),
                Memento.GetProperty("String2"),
                int.Parse(Memento.GetProperty("Int")),
                long.Parse(Memento.GetProperty("Long")),
                byte.Parse(Memento.GetProperty("Byte")),
                double.Parse(Memento.GetProperty("Double")),
                bool.Parse(Memento.GetProperty("Bool"))));
 }
コード例 #12
0
ファイル: XmlTemplater.cs プロジェクト: hp4711/structuremap
        public XmlNode SubstituteTemplates(XmlNode node, InstanceMemento memento)
        {
            var builder = new StringBuilder(_templateXml);
            foreach (string substitution in _substitutions)
            {
                string substitutionValue = memento.GetProperty(substitution);
                makeSubstitution(substitution, substitutionValue, builder);
            }

            var document = new XmlDocument();
            document.LoadXml(builder.ToString());

            return document.DocumentElement;
        }
コード例 #13
0
ファイル: XmlTemplater.cs プロジェクト: hasaki/ragetanks
        public XmlNode SubstituteTemplates(XmlNode node, InstanceMemento memento)
        {
            var builder = new StringBuilder(_templateXml);

            foreach (string substitution in _substitutions)
            {
                string substitutionValue = memento.GetProperty(substitution);
                makeSubstitution(substitution, substitutionValue, builder);
            }

            var document = new XmlDocument();

            document.LoadXml(builder.ToString());

            return(document.DocumentElement);
        }
コード例 #14
0
//        public void ChildParameter(ParameterInfo parameter)
//        {
//            copyChild(parameter.Name, parameter.ParameterType);
//        }
//
//        public void ChildArrayParameter(ParameterInfo parameter)
//        {
//            copyChildArray(parameter.Name, parameter.ParameterType.GetElementType());
//        }

        #endregion

        private void copyPrimitive(string name, bool isMandatory)
        {
            var propertyValue = _memento.GetProperty(name);

            if (propertyValue == null)
            {
                if (isMandatory)
                {
                    throw new StructureMapConfigurationException(
                              "Missing requested Instance property '{0}' for InstanceKey '{1}'", name, _memento.InstanceKey);
                }
            }
            else
            {
                _instance.Dependencies.Add(name, propertyValue);
            }
        }
コード例 #15
0
        public void StringSetter()
        {
            var          graph  = new PluginGraph();
            PluginFamily family = graph.FindFamily(typeof(IGridColumn));

            family.AddPlugin(typeof(StringGridColumn));

            InstanceMemento memento = _source.GetMemento("String");

            family.AddInstance(memento);

            var manager = new Container(graph);
            var column  = (StringGridColumn)manager.GetInstance <IGridColumn>("String");


            Assert.AreEqual(memento.GetProperty("Name"), column.Name);
        }
コード例 #16
0
        public void GetChildIsNotNull()
        {
            XmlElement element      = _memento.InnerElement;
            XmlElement childElement = element.OwnerDocument.CreateElement("rule");

            element.AppendChild(childElement);
            childElement.SetAttribute("PluggedType", "theConcreteKey");
            childElement.SetAttribute("Key", "theInstanceKey");
            childElement.SetAttribute("prop1", "thePropertyValue");

            InstanceMemento memento = _memento.GetChildMemento("rule");

            Assert.IsNotNull(memento);
            Assert.AreEqual("theInstanceKey", memento.InstanceKey);
            Assert.AreEqual("thePropertyValue", memento.GetProperty("prop1"));
            Assert.IsFalse(memento.IsDefault);
            Assert.IsFalse(memento.IsReference);
        }
コード例 #17
0
        public void GetComplex1()
        {
            InstanceMemento memento = source.GetMemento("Complex1");

            Assert.IsNotNull(memento);


            Assert.AreEqual("Complex1", memento.InstanceKey, "InstanceKey");
            Assert.AreEqual("Complex", memento.ConcreteKey, "ConcreteTypeKey");
            Assert.AreEqual("Red", memento.GetProperty("String"), "String");
            Assert.AreEqual("Green", memento.GetProperty("String2"), "String2");
            Assert.AreEqual("1", memento.GetProperty("Int"), "Int");
            Assert.AreEqual("2", memento.GetProperty("Long"), "Long");
            Assert.AreEqual("3", memento.GetProperty("Byte"), "Byte");
            Assert.AreEqual("4.5", memento.GetProperty("Double"), "Double");
            Assert.AreEqual("true", memento.GetProperty("Bool"), "Bool");
        }
コード例 #18
0
        public void PrimitiveNonStringSetter()
        {
            var          graph  = new PluginGraph();
            PluginFamily family = graph.FindFamily(typeof(IGridColumn));

            family.AddPlugin(typeof(LongGridColumn));

            InstanceMemento memento = _source.GetMemento("Long");
            long            count   = long.Parse(memento.GetProperty("Count"));

            family.AddInstance(memento);

            var manager = new Container(graph);


            var column = (LongGridColumn)manager.GetInstance <IGridColumn>("Long");

            Assert.AreEqual(count, column.Count);
        }
コード例 #19
0
        private void validateCombinedMemento(InstanceMemento combinedMemento)
        {
            Assert.AreEqual("70", combinedMemento.GetProperty("Age"));
            Assert.AreEqual("Green", combinedMemento.GetProperty("EyeColor"));

            InstanceMemento grandChildMemeto =
                combinedMemento.GetChildMemento("MyChild").GetChildMemento("MyGrandChild");
            Assert.AreEqual("1992", grandChildMemeto.GetProperty("BirthYear"));
        }