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 Create_a_referenced_instance() { MemoryInstanceMemento memento = MemoryInstanceMemento.CreateReferencedInstanceMemento("blue"); var instance = (ReferencedInstance)memento.ReadInstance(null, null); Assert.AreEqual("blue", instance.ReferenceKey); }
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 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); }
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)); }
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"); }); }
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"); }); }
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.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); }
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 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)); }
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 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); }
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>(); }
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); }
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); }
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")); }
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 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); }
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")); }
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 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 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"); }
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 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 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; }