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 BuildRuleWithABadValue() { var instance = (ConfiguredInstance)ComplexRule.GetInstance(); instance.WithProperty("Int").EqualTo("abc"); var rule = (ComplexRule)instance.Build(typeof(Rule), _session); }
/// <summary> /// Add a named complex rule. /// Complex rules are assumed to validate unless /// they throw a <see cref="RuleBasedValidationException"/>. /// </summary> /// <param name="rule">Validation rule to add.</param> public void AddRule(ComplexRule <T> rule) { _rules.Add(new RuleMetadata { Rule = obj => { rule(obj); return(true); } }); }
public void BuildRuleWithAMissingValue() { var instance = (IStructuredInstance)ComplexRule.GetInstance(); instance.RemoveKey("String"); var rule = (ComplexRule)((Instance)instance).Build(typeof(Rule), _session); }
public void build_with_a_missing_dependency_throws_configuration_exception() { var instance = ComplexRule.GetInstance(); instance.Dependencies.RemoveByName("String"); Exception <StructureMapBuildPlanException> .ShouldBeThrownBy( () => { instance.As <Instance>().Build <Rule>(_session); }); }
public void TestComplexRule() { var instance = ComplexRule.GetInstance().As <Instance>(); var rule = instance.Build <Rule>(_session); rule.ShouldNotBeNull(); rule.ShouldBeOfType <ComplexRule>(); }
public void TestComplexRule() { var instance = (ConfiguredInstance)ComplexRule.GetInstance(); var rule = (Rule)instance.Build(typeof(Rule), _session); Assert.IsNotNull(rule); Assert.IsTrue(rule is ComplexRule); }
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 void ReadPrimitivePropertiesHappyPath() { var memento = ComplexRule.GetMemento(); memento.SetPluggedType <ComplexRule>(); var instance = (IConfiguredInstance)memento.ReadInstance(new SimplePluginFactory(), 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 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 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"); }