An Spring.Objects.Factory.Support.IMethodReplacer implementation that simply returns the result of a lookup in an associated IoC container.

This class is Spring.NET's implementation of Dependency Lookup via Method Injection.

This class is reserved for internal use within the framework; it is not intended to be used by application developers using Spring.NET.

Inheritance: AbstractMethodReplacer
コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
        }