public void MakeSurePrototypeTargetIsNotNeedlesslyCreatedDuringInitialization_Unit()
        {
            GoodCommand    target = new GoodCommand();
            NopInterceptor advice = new NopInterceptor();

            MockRepository mocks   = new MockRepository();
            IObjectFactory factory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));

            ProxyFactoryObject fac = new ProxyFactoryObject();

            fac.ProxyInterfaces  = new string[] { typeof(ICommand).FullName };
            fac.IsSingleton      = false;
            fac.InterceptorNames = new string[] { "advice", "prototype" };
            fac.ObjectFactory    = factory;

//            using (mocks.Record())
            {
                using (mocks.Unordered())
                {
                    Expect.Call(factory.IsSingleton("advice")).Return(true);
                    Expect.Call(factory.GetObject("advice")).Return(advice);
                    Expect.Call(factory.GetType("prototype")).Return(target.GetType());
                    Expect.Call(factory.GetObject("prototype")).Return(target);
                }
            }
            mocks.ReplayAll();

//            using(mocks.Playback())
            {
                fac.GetObject();
            }
            mocks.VerifyAll();
        }
Beispiel #2
0
        public void MakeSurePrototypeTargetIsNotNeedlesslyCreatedDuringInitialization_Unit()
        {
            GoodCommand    target = new GoodCommand();
            NopInterceptor advice = new NopInterceptor();

            IObjectFactory factory = A.Fake <IObjectFactory>();

            ProxyFactoryObject fac = new ProxyFactoryObject();

            fac.ProxyInterfaces  = new[] { typeof(ICommand).FullName };
            fac.IsSingleton      = false;
            fac.InterceptorNames = new[] { "advice", "prototype" };
            fac.ObjectFactory    = factory;

            A.CallTo(() => factory.IsSingleton("advice")).Returns(true);
            A.CallTo(() => factory.GetObject("advice")).Returns(advice);
            A.CallTo(() => factory.GetType("prototype")).Returns(target.GetType());
            A.CallTo(() => factory.GetObject("prototype")).Returns(target);

            fac.GetObject();
        }
        public void MakeSurePrototypeTargetIsNotNeedlesslyCreatedDuringInitialization_Unit()
        {
            GoodCommand target = new GoodCommand();
            NopInterceptor advice = new NopInterceptor();

            MockRepository mocks = new MockRepository();
            IObjectFactory factory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));

            ProxyFactoryObject fac = new ProxyFactoryObject();
            fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
            fac.IsSingleton = false;
            fac.InterceptorNames = new string[] { "advice", "prototype" };
            fac.ObjectFactory = factory;

            //            using (mocks.Record())
            {
                using (mocks.Unordered())
                {
                    Expect.Call(factory.IsSingleton("advice")).Return(true);
                    Expect.Call(factory.GetObject("advice")).Return(advice);
                    Expect.Call(factory.GetType("prototype")).Return(target.GetType());
                    Expect.Call(factory.GetObject("prototype")).Return(target);
                }
            }
            mocks.ReplayAll();

            //            using(mocks.Playback())
            {
                fac.GetObject();
            }
            mocks.VerifyAll();
        }