public void EventShoudBePassedToSubscriber()
        {
            bool handled    = false;
            var  subscriber = new Subscriber(() => handled = true);
            var  source     = new EventSource();

            WeakSubscriptionManager.Subscribe(source, "Event", subscriber);
            source.Fire();
            Assert.True(handled);
        }
Esempio n. 2
0
        public void InstallerWillWireUpSubjectToPublicMethodInInternalListenerClass()
        {
            InternalListener listener = new InternalListener();
            EventSource      source   = new EventSource();
            ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();

            binder.Bind(source, listener);
            source.Fire();
            Assert.IsTrue(listener.callbackHappened);
        }
        public void EventShouldBePassedToSubscriber()
        {
            bool handled    = false;
            var  subscriber = new Subscriber(() => handled = true);
            var  source     = new EventSource();

            WeakEventHandlerManager.Subscribe <EventSource, EventArgs, Subscriber>(source, "Event",
                                                                                   subscriber.OnEvent);
            source.Fire();
            Assert.True(handled);
        }
        public void EventShouldBePassedToSubscriber()
        {
            bool handled    = false;
            var  subscriber = new Subscriber(() => handled = true);
            var  source     = new EventSource();

            EventSource.WeakEv.Subscribe(source, subscriber);

            source.Fire();
            Assert.True(handled);
        }
		public void InstallerWillWireUpSubjectToPublicMethodInInternalListenerClass()
		{
			InternalListener listener = new InternalListener();
			EventSource source = new EventSource();
			ReflectionInstrumentationBinder binder = new ReflectionInstrumentationBinder();
			binder.Bind(source, listener);

			source.Fire();

			Assert.IsTrue(listener.callbackHappened);
		}
        public void EventHandlerShouldNotBeKeptAlive()
        {
            bool handled = false;
            var  source  = new EventSource();

            AddCollectableSubscriber(source, "Event", () => handled = true);
            for (int c = 0; c < 10; c++)
            {
                GC.Collect();
                GC.Collect(3, GCCollectionMode.Forced, true);
            }
            source.Fire();
            Assert.False(handled);
        }
        public void EventShouldNotBeRaisedAfterUnsubscribe()
        {
            bool handled    = false;
            var  subscriber = new Subscriber(() => handled = true);
            var  source     = new EventSource();

            WeakEventHandlerManager.Subscribe <EventSource, EventArgs, Subscriber>(source, "Event",
                                                                                   subscriber.OnEvent);

            WeakEventHandlerManager.Unsubscribe <EventArgs, Subscriber>(source, "Event",
                                                                        subscriber.OnEvent);

            source.Fire();

            Assert.False(handled);
        }