public void AddWeakContainerListenerTest()
        {
            var listener = new TestObservable();
            IEventAggregator eventAggregator = CreateEventAggregator();

            eventAggregator.Subscribe(listener);
            eventAggregator.GetObservers().Contains(listener).ShouldBeFalse();
            eventAggregator.GetObservers().Count.ShouldEqual(0);
        }
        public void ClearTest()
        {
            var listener = new GenericHandler <object>();
            IEventAggregator eventAggregator = CreateEventAggregator();

            eventAggregator.Subscribe(listener);
            eventAggregator.GetObservers().Contains(listener).ShouldBeTrue();
            eventAggregator.GetObservers().Count.ShouldEqual(1);

            eventAggregator.Clear();
            eventAggregator.GetObservers().Count.ShouldEqual(0);
        }
        public void AddWeakListenerTest()
        {
            var listener = new GenericHandler <object>();
            IEventAggregator eventAggregator = CreateEventAggregator();

            eventAggregator.Subscribe(listener);
            eventAggregator.GetObservers().Contains(listener).ShouldBeTrue();
            eventAggregator.GetObservers().Count.ShouldEqual(1);

            listener = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            eventAggregator.GetObservers().Count.ShouldEqual(0);
        }
        public void AddInvalidListenerTest()
        {
            IEventAggregator eventAggregator = CreateEventAggregator();

            eventAggregator.Subscribe(new object()).ShouldBeFalse();
            eventAggregator.GetObservers().ShouldBeEmpty();
        }
Пример #5
0
        private void DisposeInternal()
        {
            //Disposing commands, if need.
            if (Settings.DisposeCommands)
            {
                ReflectionExtensions.DisposeCommands(this);
            }

            ClearBusy();
            ClearPropertyChangedSubscribers();
            var toRemove = _viewModelEventAggregator.GetObservers();

            for (int index = 0; index < toRemove.Count; index++)
            {
                Unsubscribe(toRemove[index]);
            }

            IViewManager viewManager;

            if (IocContainer.TryGet(out viewManager))
            {
                viewManager.CleanupViewAsync(this);
            }

            _viewModelProvider = null;
            //Disposing ioc adapter.
            if (Settings.DisposeIocContainer && _iocContainer != null)
            {
                _iocContainer.Dispose();
            }

            _disposeCancellationToken.Cancel();
            Tracer.TraceViewModel(AuditAction.Disposed, this);
            Settings.Metadata.Clear();
        }