Ejemplo n.º 1
0
        public void InstanceMethodUnsubscribeShouldBeSupported()
        {
            var listener = new GenericHandler <object>();
            IEventAggregator eventAggregator = CreateEventAggregator();
            var subscriber = eventAggregator.Subscribe <string>(listener.Handle, false);

            eventAggregator.Contains(subscriber).ShouldBeTrue();
            eventAggregator.GetSubscribers().Count.ShouldEqual(1);

            eventAggregator.Unsubscribe <object>(listener.Handle);
            eventAggregator.GetSubscribers().ShouldBeEmpty();
        }
Ejemplo n.º 2
0
        public void InstanceNonWeakMethodShouldBeSupported()
        {
            var message  = new object();
            var listener = new GenericHandler <object>();
            IEventAggregator eventAggregator = CreateEventAggregator();
            var subscriber = eventAggregator.Subscribe <object>(listener.Handle, false);

            eventAggregator.Contains(subscriber).ShouldBeTrue();
            eventAggregator.GetSubscribers().Count.ShouldEqual(1);

            eventAggregator.Publish(eventAggregator, message);
            listener.Sender.ShouldEqual(eventAggregator);
            listener.Message.ShouldEqual(message);
            listener.Count.ShouldEqual(1);

            listener = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            eventAggregator.Contains(subscriber).ShouldBeTrue();
        }
Ejemplo n.º 3
0
        public void ClearTest()
        {
            var listener = new GenericHandler <object>();
            IEventAggregator eventAggregator = CreateEventAggregator();
            var subscriber = eventAggregator.Subscribe(listener);

            eventAggregator.Contains(subscriber).ShouldBeTrue();
            eventAggregator.GetSubscribers().Count.ShouldEqual(1);

            eventAggregator.UnsubscribeAll();
            eventAggregator.GetSubscribers().Count.ShouldEqual(0);
        }
Ejemplo n.º 4
0
        public void AddWeakListenerTest()
        {
            var listener = new GenericHandler <object>();
            IEventAggregator eventAggregator = CreateEventAggregator();
            var subscriber = eventAggregator.Subscribe(listener);

            eventAggregator.Contains(subscriber).ShouldBeTrue();
            eventAggregator.GetSubscribers().Count.ShouldEqual(1);

            listener = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            eventAggregator.GetSubscribers().Count.ShouldEqual(0);
        }
Ejemplo n.º 5
0
        public void NonWeakLambdaMethodShouldBeSupported()
        {
            var message = new object();
            IEventAggregator eventAggregator = CreateEventAggregator();
            bool             isInvoked       = false;
            var subscriber = eventAggregator.Subscribe <object>((arg1, arg2) =>
            {
                arg1.ShouldEqual(eventAggregator);
                arg2.ShouldEqual(message);
                isInvoked = true;
            }, false);

            eventAggregator.Contains(subscriber).ShouldBeTrue();
            eventAggregator.GetSubscribers().Count.ShouldEqual(1);
            eventAggregator.Publish(eventAggregator, message);
            isInvoked.ShouldBeTrue();
        }