public void ObjectNameChild() { ObjectDefinitionBuilder odb = ObjectDefinitionBuilder.ChildObjectDefinition(odf, typeof(TestObject).FullName); ChildObjectDefinition rod = odb.ObjectDefinition as ChildObjectDefinition; Assert.IsNotNull(rod); Assert.IsFalse(rod.HasObjectType); Assert.AreEqual(typeof(TestObject).FullName, rod.ParentName); }
public void Ctor_ParentNameOnly() { const string expectedParentName = "foo"; ChildObjectDefinition def = new ChildObjectDefinition(expectedParentName); Assert.AreEqual(expectedParentName, def.ParentName, "ParentName property not initialized correctly by ctor."); Assert.IsNotNull(def.PropertyValues, "PropertyValues must be init'd to a non-null collection if not explicitly supplied."); Assert.AreEqual(0, def.PropertyValues.PropertyValues.Count, "PropertyValues must be init'd to an empty collection if not explicitly supplied."); }
/// <summary> /// Factory style method for getting concrete /// <see cref="IConfigurableObjectDefinition"/> /// instances. /// </summary> /// /// <remarks>If no parent is specified, a RootObjectDefinition is created, otherwise a /// ChildObjectDefinition.</remarks> /// <param name="typeName">The <see cref="System.Type"/> of the defined object.</param> /// <param name="parent">The name of the parent object definition (if any).</param> /// <param name="domain">The <see cref="System.AppDomain"/> against which any class names /// will be resolved into <see cref="System.Type"/> instances.</param> /// <returns> /// An /// <see cref="IConfigurableObjectDefinition"/> /// instance. /// </returns> public virtual AbstractObjectDefinition CreateObjectDefinition(string typeName, string parent, AppDomain domain) { Type objectType = null; if (StringUtils.HasText(typeName) && domain != null) { try { objectType = TypeResolutionUtils.ResolveType(typeName); } // try later.... catch { } } if (StringUtils.IsNullOrEmpty(parent)) { if (objectType != null) { return(new RootObjectDefinition(objectType)); } else { RootObjectDefinition rootObjectDefinition = new RootObjectDefinition(); rootObjectDefinition.ObjectTypeName = typeName; return(rootObjectDefinition); } } else { if (objectType != null) { ChildObjectDefinition childObjectDefinition = new ChildObjectDefinition(parent); childObjectDefinition.ObjectType = objectType; return(childObjectDefinition); } else { ChildObjectDefinition childObjectDefinition = new ChildObjectDefinition(parent); childObjectDefinition.ObjectTypeName = typeName; return(childObjectDefinition); } } }
public void OverrideFromOther() { RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), AutoWiringMode.Constructor); rod.IsSingleton = false; rod.InitMethodName = "Umberto Eco"; rod.DestroyMethodName = "Pedulismus"; rod.ConstructorArgumentValues = new ConstructorArgumentValues(); rod.ConstructorArgumentValues.AddGenericArgumentValue("Wulf", "Sternhammer"); rod.DependencyCheck = DependencyCheckingMode.Objects; rod.DependsOn = new string[] { "Jimmy", "Joyce" }; rod.IsAbstract = true; rod.IsLazyInit = true; rod.FactoryMethodName = "IfINeedYouIllJustUseYourSimpleName"; rod.FactoryObjectName = "PerspirationShop"; rod.ResourceDescription = "Ohhh"; rod.PropertyValues = new MutablePropertyValues(); rod.PropertyValues.Add("Age", 100); rod.EventHandlerValues = new EventValues(); InstanceEventHandlerValue handler = new InstanceEventHandlerValue(new TestObject(), "Ping"); handler.EventName = "Bing"; rod.EventHandlerValues.AddHandler(handler); ChildObjectDefinition cod = new ChildObjectDefinition("parent"); cod.ObjectTypeName = "ChildObjectTypeName"; cod.IsSingleton = true; cod.AutowireMode = AutoWiringMode.ByType; cod.InitMethodName = "InitChild"; cod.DestroyMethodName = "DestroyChild"; cod.ConstructorArgumentValues = new ConstructorArgumentValues(); cod.ConstructorArgumentValues.AddNamedArgumentValue("ctorarg", "ctorarg-value"); cod.DependencyCheck = DependencyCheckingMode.None; cod.DependsOn = new string[] { "Aleks", "Mark" }; cod.IsAbstract = false; cod.IsLazyInit = false; cod.FactoryMethodName = "ChildFactoryMethodName"; cod.FactoryObjectName = "ChildFactoryObjectName"; cod.ResourceDescription = "ChildResourceDescription"; cod.PropertyValues = new MutablePropertyValues(); cod.PropertyValues.Add("Prop1", "Val1"); cod.PropertyValues.Add("Age", 50); cod.EventHandlerValues = new EventValues(); handler = new InstanceEventHandlerValue(new TestObject(), "Pong"); handler.EventName = "Bong"; cod.EventHandlerValues.AddHandler(handler); rod.OverrideFrom(cod); // ... Assert.AreEqual("ChildObjectTypeName", rod.ObjectTypeName); Assert.AreEqual(AutoWiringMode.ByType, rod.AutowireMode); Assert.AreEqual(true, rod.IsSingleton); Assert.AreEqual("InitChild", rod.InitMethodName); Assert.AreEqual("DestroyChild", rod.DestroyMethodName); Assert.AreEqual(DependencyCheckingMode.None, rod.DependencyCheck); Assert.AreEqual(4, rod.DependsOn.Count); Assert.AreEqual(false, rod.IsAbstract); Assert.AreEqual(false, rod.IsLazyInit); Assert.AreEqual("ChildFactoryMethodName", rod.FactoryMethodName); Assert.AreEqual("ChildFactoryObjectName", rod.FactoryObjectName); Assert.AreEqual("ChildResourceDescription", rod.ResourceDescription); Assert.AreEqual(2, rod.ConstructorArgumentValues.ArgumentCount); Assert.AreEqual(2, rod.PropertyValues.PropertyValues.Count); Assert.AreEqual("Val1", rod.PropertyValues.GetPropertyValue("Prop1").Value); Assert.AreEqual(50, rod.PropertyValues.GetPropertyValue("Age").Value); Assert.AreEqual(2, rod.EventHandlerValues.Events.Count); }