Esempio n. 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();
        }