public void SunnyDayPath() { IObjectFactory mockFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition mockDefinition = (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition)); IMethodReplacer mockReplacer = (IMethodReplacer)mocks.CreateMock(typeof(IMethodReplacer)); const string ReplacerObjectName = "replacer"; Expect.Call(mockFactory.GetObject(ReplacerObjectName)).Return(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(mockDefinition.MethodOverrides).Return(overrides); Expect.Call(mockReplacer.Implement(null, null, null)).IgnoreArguments().Return(null); mocks.ReplayAll(); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); mocks.VerifyAll(); }
public void SunnyDayPath() { IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition configurableObjectDefinition = (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition)); object expectedLookup = new object(); const string LookupObjectName = "foo"; Expect.Call(objectFactory.GetObject(LookupObjectName)).Return(expectedLookup); LookupMethodOverride ovr = new LookupMethodOverride("SunnyDayPath", LookupObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(configurableObjectDefinition.MethodOverrides).Return(overrides); LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory); mocks.ReplayAll(); MethodInfo method = (MethodInfo) MethodBase.GetCurrentMethod(); object lookup = replacer.Implement(this, method, new object[] {}); Assert.AreSame(expectedLookup, lookup); mocks.VerifyAll(); }
protected AbstractObjectDefinition(SerializationInfo info, StreamingContext context) { constructorArgumentValues = (ConstructorArgumentValues)info.GetValue("constructorArgumentValues", typeof(ConstructorArgumentValues)); propertyValues = (MutablePropertyValues)info.GetValue("propertyValues", typeof(MutablePropertyValues)); eventHandlerValues = (EventValues)info.GetValue("eventHandlerValues", typeof(EventValues)); methodOverrides = (MethodOverrides)info.GetValue("methodOverrides", typeof(MethodOverrides)); resourceDescription = info.GetString("resourceDescription"); isSingleton = info.GetBoolean("isSingleton"); isPrototype = info.GetBoolean("isPrototype"); isLazyInit = info.GetBoolean("isLazyInit"); isAbstract = info.GetBoolean("isAbstract"); scope = info.GetString("scope"); role = (ObjectRole)info.GetValue("role", typeof(ObjectRole)); var objectTypeName = info.GetString("objectTypeName"); objectType = objectTypeName != null?Type.GetType(objectTypeName) : null; autowireMode = (AutoWiringMode)info.GetValue("autowireMode", typeof(AutoWiringMode)); dependencyCheck = (DependencyCheckingMode)info.GetValue("dependencyCheck", typeof(DependencyCheckingMode)); dependsOn = (IList <string>)info.GetValue("dependsOn", typeof(IList <string>)); autowireCandidate = info.GetBoolean("autowireCandidate"); primary = info.GetBoolean("primary"); qualifiers = (IDictionary <string, AutowireCandidateQualifier>)info.GetValue("qualifiers", typeof(IDictionary <string, AutowireCandidateQualifier>)); initMethodName = info.GetString("initMethodName"); destroyMethodName = info.GetString("destroyMethodName"); factoryMethodName = info.GetString("factoryMethodName"); factoryObjectName = info.GetString("factoryObjectName"); }
public void SunnyDayPath() { IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition configurableObjectDefinition = (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition)); object expectedLookup = new object(); const string LookupObjectName = "foo"; Expect.Call(objectFactory.GetObject(LookupObjectName)).Return(expectedLookup); LookupMethodOverride ovr = new LookupMethodOverride("SunnyDayPath", LookupObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(configurableObjectDefinition.MethodOverrides).Return(overrides); LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory); mocks.ReplayAll(); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); object lookup = replacer.Implement(this, method, new object[] {}); Assert.AreSame(expectedLookup, lookup); mocks.VerifyAll(); }
/// <summary> /// Copy all given method overrides into this object. /// </summary> /// <param name="other"> /// The overrides to be copied into this object. /// </param> public void AddAll(MethodOverrides other) { if (other != null) { Overrides.AddAll(other.Overrides); _overloadedMethodNames.AddAll(other._overloadedMethodNames); } }
/// <summary> /// Override settings in this object definition from the supplied /// <paramref name="other"/> object definition. /// </summary> /// <param name="other"> /// The object definition used to override the member fields of this instance. /// </param> public virtual void OverrideFrom(IObjectDefinition other) { AssertUtils.ArgumentNotNull(other, "other"); IsAbstract = other.IsAbstract; Scope = other.Scope; IsLazyInit = other.IsLazyInit; ConstructorArgumentValues.AddAll(other.ConstructorArgumentValues); PropertyValues.AddAll(other.PropertyValues.PropertyValues); EventHandlerValues.AddAll(other.EventHandlerValues); if (StringUtils.HasText(other.ObjectTypeName)) { ObjectTypeName = other.ObjectTypeName; } if (StringUtils.HasText(other.InitMethodName)) { InitMethodName = other.InitMethodName; } if (StringUtils.HasText(other.DestroyMethodName)) { DestroyMethodName = other.DestroyMethodName; } if (StringUtils.HasText(other.FactoryObjectName)) { FactoryObjectName = other.FactoryObjectName; } if (StringUtils.HasText(other.FactoryMethodName)) { FactoryMethodName = other.FactoryMethodName; } if (other.DependsOn != null && other.DependsOn.Count > 0) { List <string> deps = new List <string>(other.DependsOn); if (DependsOn != null && DependsOn.Count > 0) { deps.AddRange(DependsOn); } DependsOn = deps; } AutowireMode = other.AutowireMode; ResourceDescription = other.ResourceDescription; IsPrimary = other.IsPrimary; IsAutowireCandidate = other.IsAutowireCandidate; AbstractObjectDefinition aod = other as AbstractObjectDefinition; if (aod != null) { if (aod.HasObjectType) { ObjectType = other.ObjectType; } MethodOverrides.AddAll(aod.MethodOverrides); DependencyCheck = aod.DependencyCheck; CopyQualifiersFrom(aod); } }
/// <summary> /// Override settings in this object definition from the supplied /// <paramref name="other"/> object definition. /// </summary> /// <param name="other"> /// The object definition used to override the member fields of this instance. /// </param> public virtual void OverrideFrom(IObjectDefinition other) { AssertUtils.ArgumentNotNull(other, "other"); IsAbstract = other.IsAbstract; Scope = other.Scope; IsLazyInit = other.IsLazyInit; ConstructorArgumentValues.AddAll(other.ConstructorArgumentValues); PropertyValues.AddAll(other.PropertyValues.PropertyValues); EventHandlerValues.AddAll(other.EventHandlerValues); if (StringUtils.HasText(other.ObjectTypeName)) { ObjectTypeName = other.ObjectTypeName; } if (StringUtils.HasText(other.InitMethodName)) { InitMethodName = other.InitMethodName; } if (StringUtils.HasText(other.DestroyMethodName)) { DestroyMethodName = other.DestroyMethodName; } if (StringUtils.HasText(other.FactoryObjectName)) { FactoryObjectName = other.FactoryObjectName; } if (StringUtils.HasText(other.FactoryMethodName)) { FactoryMethodName = other.FactoryMethodName; } if (ArrayUtils.HasLength(other.DependsOn)) { ArrayList deps = new ArrayList(other.DependsOn); if (ArrayUtils.HasLength(DependsOn)) { deps.AddRange(DependsOn); } DependsOn = (string[])deps.ToArray(typeof(string)); } AutowireMode = other.AutowireMode; ResourceDescription = other.ResourceDescription; AbstractObjectDefinition aod = other as AbstractObjectDefinition; if (aod != null) { if (aod.HasObjectType) { ObjectType = other.ObjectType; } MethodOverrides.AddAll(aod.MethodOverrides); DependencyCheck = aod.DependencyCheck; } }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinition"/> /// class. /// </summary> /// <param name="other"> /// The object definition used to initialise the member fields of this /// instance. /// </param> /// <remarks> /// <p> /// This is an <see langword="abstract"/> class, and as such exposes no /// public constructors. /// </p> /// </remarks> protected AbstractObjectDefinition(IObjectDefinition other) { AssertUtils.ArgumentNotNull(other, "other"); OverrideFrom(other); AbstractObjectDefinition aod = other as AbstractObjectDefinition; if (aod != null) { if (aod.HasObjectType) { ObjectType = other.ObjectType; } else { ObjectTypeName = other.ObjectTypeName; } MethodOverrides = new MethodOverrides(aod.MethodOverrides); DependencyCheck = aod.DependencyCheck; } ParentName = other.ParentName; IsAbstract = other.IsAbstract; // IsSingleton = other.IsSingleton; Scope = other.Scope; Role = other.Role; IsLazyInit = other.IsLazyInit; ConstructorArgumentValues = new ConstructorArgumentValues(other.ConstructorArgumentValues); PropertyValues = new MutablePropertyValues(other.PropertyValues); EventHandlerValues = new EventValues(other.EventHandlerValues); InitMethodName = other.InitMethodName; DestroyMethodName = other.DestroyMethodName; IsAutowireCandidate = other.IsAutowireCandidate; IsPrimary = other.IsPrimary; CopyQualifiersFrom(aod); if (other.DependsOn.Count > 0) { DependsOn = other.DependsOn; } FactoryMethodName = other.FactoryMethodName; FactoryObjectName = other.FactoryObjectName; AutowireMode = other.AutowireMode; ResourceDescription = other.ResourceDescription; }
/// <summary> /// Copy all given method overrides into this object. /// </summary> /// <param name="other"> /// The overrides to be copied into this object. /// </param> public void AddAll(MethodOverrides other) { if (other != null) { if (other._overrides != null && other._overrides.Count > 0) { _overrides = _overrides ?? new HashSet <MethodOverride>(); foreach (var @override in other._overrides) { _overrides.Add(@override); } } if (other._overloadedMethodNames != null && other._overloadedMethodNames.Count > 0) { _overloadedMethodNames = _overloadedMethodNames ?? new HashSet <string>(); foreach (var methodName in other._overloadedMethodNames) { _overloadedMethodNames.Add(methodName); } } } }
public void SunnyDayPath() { IObjectFactory mockFactory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory)); IConfigurableObjectDefinition mockDefinition = (IConfigurableObjectDefinition) mocks.CreateMock(typeof(IConfigurableObjectDefinition)); IMethodReplacer mockReplacer = (IMethodReplacer) mocks.CreateMock(typeof(IMethodReplacer)); const string ReplacerObjectName = "replacer"; Expect.Call(mockFactory.GetObject(ReplacerObjectName)).Return(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); Expect.Call(mockDefinition.MethodOverrides).Return(overrides); Expect.Call(mockReplacer.Implement(null, null, null)).IgnoreArguments().Return(null); mocks.ReplayAll(); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo) MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); mocks.VerifyAll(); }
public void SunnyDayPath() { var objectFactory = A.Fake <IObjectFactory>(); var configurableObjectDefinition = A.Fake <IConfigurableObjectDefinition>(); object expectedLookup = new object(); const string LookupObjectName = "foo"; A.CallTo(() => objectFactory.GetObject(LookupObjectName)).Returns(expectedLookup); LookupMethodOverride ovr = new LookupMethodOverride("SunnyDayPath", LookupObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); A.CallTo(() => configurableObjectDefinition.MethodOverrides).Returns(overrides); LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); object lookup = replacer.Implement(this, method, new object[] {}); Assert.AreSame(expectedLookup, lookup); }
public void SunnyDayPath() { IObjectFactory mockFactory = A.Fake <IObjectFactory>(); IConfigurableObjectDefinition mockDefinition = A.Fake <IConfigurableObjectDefinition>(); IMethodReplacer mockReplacer = A.Fake <IMethodReplacer>(); const string ReplacerObjectName = "replacer"; A.CallTo(() => mockFactory.GetObject(ReplacerObjectName)).Returns(mockReplacer); ReplacedMethodOverride ovr = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName); MethodOverrides overrides = new MethodOverrides(); overrides.Add(ovr); A.CallTo(() => mockDefinition.MethodOverrides).Returns(overrides); A.CallTo(() => mockReplacer.Implement(null, null, null)).WithAnyArguments().Returns(null); DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory); MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); replacer.Implement(this, method, new object[] {}); }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinition"/> /// class. /// </summary> /// <param name="other"> /// The object definition used to initialise the member fields of this /// instance. /// </param> /// <remarks> /// <p> /// This is an <see langword="abstract"/> class, and as such exposes no /// public constructors. /// </p> /// </remarks> protected AbstractObjectDefinition(IObjectDefinition other) { AssertUtils.ArgumentNotNull(other, "other"); this.OverrideFrom(other); AbstractObjectDefinition aod = other as AbstractObjectDefinition; if (aod != null) { if (aod.HasObjectType) { ObjectType = other.ObjectType; } else { ObjectTypeName = other.ObjectTypeName; } MethodOverrides = new MethodOverrides(aod.MethodOverrides); DependencyCheck = aod.DependencyCheck; } ParentName = other.ParentName; IsAbstract = other.IsAbstract; // IsSingleton = other.IsSingleton; Scope = other.Scope; Role = other.Role; IsLazyInit = other.IsLazyInit; ConstructorArgumentValues = new ConstructorArgumentValues(other.ConstructorArgumentValues); PropertyValues = new MutablePropertyValues(other.PropertyValues); EventHandlerValues = new EventValues(other.EventHandlerValues); InitMethodName = other.InitMethodName; DestroyMethodName = other.DestroyMethodName; DependsOn = new string[other.DependsOn.Length]; IsAutowireCandidate = other.IsAutowireCandidate; Array.Copy(other.DependsOn, DependsOn, other.DependsOn.Length); FactoryMethodName = other.FactoryMethodName; FactoryObjectName = other.FactoryObjectName; AutowireMode = other.AutowireMode; ResourceDescription = other.ResourceDescription; }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.Support.MethodOverrides"/> class. /// </summary> /// <remarks> /// <p> /// Deep copy constructoe. /// </p> /// </remarks> /// <param name="other"> /// The instance supplying initial overrides for this new instance. /// </param> public MethodOverrides(MethodOverrides other) { AddAll(other); }
/// <summary> /// Parse <see cref="ObjectDefinitionConstants.ReplacedMethodElement"/> element and add parsed element to <paramref name="overrides"/> /// </summary> protected void ParseReplacedMethodElement( string name, MethodOverrides overrides, XmlElement element, ParserContext parserContext) { string methodName = GetAttributeValue(element, ObjectDefinitionConstants.ReplacedMethodNameAttribute); string targetReplacerObjectName = GetAttributeValue(element, ObjectDefinitionConstants.ReplacedMethodReplacerNameAttribute); if (StringUtils.IsNullOrEmpty(methodName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.ReplacedMethodNameAttribute, ObjectDefinitionConstants.ReplacedMethodElement)); } if (StringUtils.IsNullOrEmpty(targetReplacerObjectName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.ReplacedMethodReplacerNameAttribute, ObjectDefinitionConstants.ReplacedMethodElement)); } ReplacedMethodOverride theOverride = new ReplacedMethodOverride(methodName, targetReplacerObjectName); foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.ReplacedMethodArgumentTypeElement)) { XmlElement argElement = (XmlElement)node; string match = GetAttributeValue(argElement, ObjectDefinitionConstants.ReplacedMethodArgumentTypeMatchAttribute); if (StringUtils.IsNullOrEmpty(match)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.ReplacedMethodArgumentTypeMatchAttribute, ObjectDefinitionConstants.ReplacedMethodArgumentTypeElement)); } theOverride.AddTypeIdentifier(match); } overrides.Add(theOverride); }
/// <summary> /// Parse <see cref="ObjectDefinitionConstants.LookupMethodElement"/> element and add parsed element to <paramref name="overrides"/> /// </summary> protected void ParseLookupMethodElement( string name, MethodOverrides overrides, XmlElement element, ParserContext parserContext) { string methodName = GetAttributeValue(element, ObjectDefinitionConstants.LookupMethodNameAttribute); string targetObjectName = GetAttributeValue(element, ObjectDefinitionConstants.LookupMethodObjectNameAttribute); if (StringUtils.IsNullOrEmpty(methodName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.LookupMethodNameAttribute, ObjectDefinitionConstants.LookupMethodElement)); } if (StringUtils.IsNullOrEmpty(targetObjectName)) { throw new ObjectDefinitionStoreException( parserContext.ReaderContext.Resource, name, string.Format("The '{0}' attribute is required for the '{1}' element.", ObjectDefinitionConstants.LookupMethodObjectNameAttribute, ObjectDefinitionConstants.LookupMethodElement)); } overrides.Add(new LookupMethodOverride(methodName, targetObjectName)); }
/// <summary> /// Parse method override argument subelements of the given object element. /// </summary> protected MethodOverrides ParseMethodOverrideSubElements( string name, XmlElement element, ParserContext parserContext) { MethodOverrides overrides = new MethodOverrides(); foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.LookupMethodElement)) { ParseLookupMethodElement(name, overrides, (XmlElement)node, parserContext); } foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.ReplacedMethodElement)) { ParseReplacedMethodElement(name, overrides, (XmlElement)node, parserContext); } return overrides; }
/// <summary> /// Copy all given method overrides into this object. /// </summary> /// <param name="other"> /// The overrides to be copied into this object. /// </param> public void AddAll(MethodOverrides other) { if (other != null) { Overrides.AddAll(other.Overrides); _overloadedMethodNames.AddAll(other._overloadedMethodNames); } }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.Support.MethodOverrides"/> class. /// </summary> /// <remarks> /// <p> /// Deep copy constructoe. /// </p> /// </remarks> /// <param name="other"> /// The instance supplying initial overrides for this new instance. /// </param> public MethodOverrides(MethodOverrides other) { AddAll(other); }