public void NotifyGenericMessageTest() { var listenerAlpha = new GenericHandler <Alpha>(); var listenerBeta = new GenericHandler <Beta>(); IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listenerAlpha); eventAggregator.Subscribe(listenerBeta); //Publish about alpha. var alpha = new Alpha(); eventAggregator.Publish(eventAggregator, alpha); listenerAlpha.Count.ShouldEqual(1); listenerAlpha.Message.ShouldEqual(alpha); listenerAlpha.Sender.ShouldEqual(eventAggregator); listenerBeta.Count.ShouldEqual(0); //Publish about beta. var beta = new Beta(); eventAggregator.Publish(eventAggregator, beta); listenerAlpha.Count.ShouldEqual(2); listenerAlpha.Message.ShouldEqual(beta); listenerAlpha.Sender.ShouldEqual(eventAggregator); listenerBeta.Count.ShouldEqual(1); listenerBeta.Message.ShouldEqual(beta); listenerBeta.Sender.ShouldEqual(eventAggregator); }
public void NotifySelfShouldNotThrowExceptionTest() { var listener = new GenericHandler <object>(); var containerListener = new GenericHandler <object>(); var observable = new TestObservable(); observable.Subscribe(containerListener); IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listener); eventAggregator.Subscribe(observable); observable.Subscribe(new TestObservable { Listeners = eventAggregator }); eventAggregator.Publish(this, eventAggregator); listener.Count.ShouldEqual(1); listener.Sender.ShouldEqual(this); listener.Message.ShouldEqual(eventAggregator); containerListener.Count.ShouldEqual(0); containerListener.Sender.ShouldBeNull(); containerListener.Message.ShouldBeNull(); }
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(); }
public void NotifyOneListenerTest() { var listener = new GenericHandler <object>(); IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listener); eventAggregator.Publish(this, eventAggregator); listener.Count.ShouldEqual(1); listener.Sender.ShouldEqual(this); listener.Message.ShouldEqual(eventAggregator); }
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); }
public void RemoveWeakListenerTest() { var listener = new GenericHandler <object>(); IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listener); eventAggregator.GetObservers().Contains(listener).ShouldBeTrue(); eventAggregator.GetObservers().Count.ShouldEqual(1); eventAggregator.Unsubscribe(listener).ShouldBeTrue(); eventAggregator.GetObservers().Count.ShouldEqual(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); }
public void NotifyListenerWithEmptyContainerTest() { var listener = new GenericHandler <object>(); var observable = new TestObservable { Listeners = null }; IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listener); eventAggregator.Subscribe(observable); eventAggregator.Publish(this, eventAggregator); listener.Count.ShouldEqual(1); listener.Sender.ShouldEqual(this); listener.Message.ShouldEqual(eventAggregator); }
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(); }
public void NotifyListenerWithContainerTest() { var listener = new GenericHandler <object>(); var containerListener = new GenericHandler <object>(); var stateChanged = new TestObservable(); stateChanged.Subscribe(containerListener); IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listener); eventAggregator.Subscribe(stateChanged); eventAggregator.Publish(this, eventAggregator); listener.Count.ShouldEqual(1); listener.Sender.ShouldEqual(this); listener.Message.ShouldEqual(eventAggregator); containerListener.Count.ShouldEqual(0); containerListener.Sender.ShouldBeNull(); containerListener.Message.ShouldBeNull(); }