예제 #1
0
        public void SunnyDayPath()
        {
            IObjectFactory mockFactory = mocks.StrictMock <IObjectFactory>();
            IConfigurableObjectDefinition mockDefinition = mocks.StrictMock <IConfigurableObjectDefinition>();
            IMethodReplacer mockReplacer = mocks.StrictMock <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 = mocks.StrictMock <IObjectFactory>();
            var configurableObjectDefinition = mocks.StrictMock <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();
        }
예제 #3
0
 /// <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>
        /// Creates a new instance of the
        /// <see cref="Oragon.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;
            IsAutowireCandidate = other.IsAutowireCandidate;
            IsPrimary           = other.IsPrimary;
            CopyQualifiersFrom(aod);
            DependsOn           = new List <string>(other.DependsOn);
            FactoryMethodName   = other.FactoryMethodName;
            FactoryObjectName   = other.FactoryObjectName;
            AutowireMode        = other.AutowireMode;
            ResourceDescription = other.ResourceDescription;
        }
예제 #6
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Oragon.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);
 }