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 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 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 AddInvalidListenerTest() { IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(new object()).ShouldBeNull(); eventAggregator.GetSubscribers().ShouldBeEmpty(); }
private void DisposeInternal() { if (Settings.DisposeCommands) { ReflectionExtensions.DisposeCommands(this); } this.ClearBusy(); ClearPropertyChangedSubscribers(); if (InitializeEventAggregator(false)) { var toRemove = _localEventAggregator.GetSubscribers(); for (int index = 0; index < toRemove.Count; index++) { Unsubscribe(toRemove[index]); } } IViewManager viewManager; if (IocContainer.TryGet(out viewManager)) { viewManager.CleanupViewAsync(this); } if (Settings.DisposeIocContainer && _iocContainer != null && !ReferenceEquals(_iocContainer, ServiceProvider.IocContainer)) { _iocContainer.Dispose(); } Settings.Metadata.Clear(); ServiceProvider.AttachedValueProvider.Clear(this); Tracer.TraceViewModel(AuditAction.Disposed, this); }
private void DisposeInternal() { this.ClearBusy(); ClearPropertyChangedSubscribers(); if (InitializeEventAggregator(false)) { var toRemove = _localEventAggregator.GetSubscribers(); for (int index = 0; index < toRemove.Count; index++) { Unsubscribe(toRemove[index]); } } IViewManager viewManager; if (IocContainer.TryGet(out viewManager)) { viewManager.CleanupViewAsync(this); } Settings.Metadata.Clear(); ServiceProvider.AttachedValueProvider.Clear(this); CleanupWeakReference(); Tracer.TraceViewModel(ViewModelLifecycleType.Disposed, this); }
public void AddWeakContainerListenerTest() { var listener = new TestObservable(); IEventAggregator eventAggregator = CreateEventAggregator(); eventAggregator.Subscribe(listener); eventAggregator.GetSubscribers().Count.ShouldEqual(0); }
public void WeakMethodShouldBeSupported() { var message = new object(); var listener = new GenericHandler <object>(); IEventAggregator eventAggregator = CreateEventAggregator(); var subscriber = eventAggregator.Subscribe <object>(listener.Handle); 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.GetSubscribers().ShouldBeEmpty(); }
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(); }
public static IList <object> GetObservers(this IEventAggregator aggregator) { return(aggregator.GetSubscribers().Select(subscriber => subscriber.Target).ToList()); }