public void DisposeTriggerWhenDisposed ()
		{
		    DynamicMock mock = new DynamicMock(typeof(ITrigger));
            ITrigger trigger = (ITrigger) mock.Object;            

            mock.Expect("Dispose");
            AggregatedDeployEventDispatcher dispatcher = new AggregatedDeployEventDispatcher(trigger);
            dispatcher.Dispose();
            mock.Verify();
		}
		public void testIntroductionInterceptorWithDelegation()
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ITimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);
	
			IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction));
			ITimeStampedIntroduction ts = (ITimeStampedIntroduction) tsControl.Object;
			tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);

			DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
			factory.AddIntroduction(advisor);

			ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
	
			tsControl.Verify();
		}
 public void DisposeDispatcherOnDispose ()
 {
     DynamicMock mock = new DynamicMock (typeof (IDeployEventDispatcher));
     IDeployEventDispatcher dispatcher = (IDeployEventDispatcher) mock.Object;
     mock.Expect ("Dispose");
     IDeployLocation location = new FileSystemDeployLocation (dispatcher, deployPath);
     location.Dispose ();
     mock.Verify ();
 }
Ejemplo n.º 4
0
        public void RemoveAdvisedSupportListener()
        {
            IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
            IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;

            ProxyFactory factory = new ProxyFactory(new TestObject());
            factory.AddListener(listener);
            factory.RemoveListener(listener);

            factory.GetProxy();

            // check that no lifecycle callback methods were invoked on the listener...
            mock.Verify();
        }
Ejemplo n.º 5
0
        public void AdvisedSupportListenerMethodsAre_NOT_CalledIfProxyHasNotBeenCreated()
        {
            IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
            IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;

            ProxyFactory factory = new ProxyFactory(new TestObject());
            factory.AddListener(listener);

            // must not fire the AdviceChanged callback...
            factory.AddAdvice(new NopInterceptor());
            // must not fire the InterfacesChanged callback...
            factory.AddInterface(typeof(ISerializable));

            mock.Verify();
        }
Ejemplo n.º 6
0
        public void AdvisedSupportListenerMethodsAreCalledAppropriately()
        {
            IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
            IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;

            mock.Expect("Activated");
            mock.Expect("AdviceChanged");
            mock.Expect("InterfacesChanged");

            ProxyFactory factory = new ProxyFactory(new TestObject());
            factory.AddListener(listener);

            // must fire the Activated callback...
            factory.GetProxy();
            // must fire the AdviceChanged callback...
            factory.AddAdvice(new NopInterceptor());
            // must fire the InterfacesChanged callback...
            factory.AddInterface(typeof(ISerializable));

            mock.Verify();
        }
		public void WithNonSingletonTargetObject()
		{
			IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));
			const string objectName = "Foo";
			mock.ExpectAndReturn("IsPrototype", false, objectName);
			PrototypeTargetSource source = new PrototypeTargetSource();
			source.TargetObjectName = objectName;
			try
			{
				source.ObjectFactory = (IObjectFactory) mock.Object;
				Assert.Fail("Should have thrown an ObjectDefinitionStoreException by this point.");
			}
			catch (ObjectDefinitionStoreException)
			{
				mock.Verify();
			}
		}
		public void TargetType()
		{
			SideEffectObject target = new SideEffectObject();
			IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));
			mock.ExpectAndReturn("IsPrototype", true, null);
			mock.ExpectAndReturn("GetType", typeof(SideEffectObject), null);
			PrototypeTargetSource source = new PrototypeTargetSource();
			source.ObjectFactory = (IObjectFactory) mock.Object;
			Assert.AreEqual(target.GetType(), source.TargetType, "Wrong TargetType being returned.");
			mock.Verify();
		}
		public void GetTarget()
		{
			SideEffectObject target = new SideEffectObject();
			IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));;
			mock.ExpectAndReturn("IsPrototype", true, "foo");
			mock.ExpectAndReturn("GetObject", target, "foo");
		    mock.ExpectAndReturn("GetType", typeof (string), "foo");
			PrototypeTargetSource source = new PrototypeTargetSource();
            source.TargetObjectName = "foo";
			source.ObjectFactory = (IObjectFactory) mock.Object;
			Assert.IsTrue(object.ReferenceEquals(source.GetTarget(), target),
			              "Initial target source reference not being returned by GetTarget().");
			mock.Verify();
		}
		public void testIntroductionInterceptorWithInterfaceHierarchy() 
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ISubTimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);

			IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction));
			ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction) tsControl.Object;
			tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);

			DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
			// we must add introduction, not an advisor
			factory.AddIntroduction(advisor);

			object proxy = factory.GetProxy();
			ISubTimeStamped tsp = (ISubTimeStamped) proxy;
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);

			tsControl.Verify();
		}