Exemplo n.º 1
0
            public void SupportsCustomCollections()
            {
                var source   = new CustomObservableCollection();
                var listener = new EventListener();

                var weakEventListener = listener.SubscribeToWeakCollectionChangedEvent(source, listener.OnCollectionChangedEvent);

                Assert.AreEqual(0, listener.CollectionChangedEventCount);

                source.Add(DateTime.Now);

                Assert.AreEqual(1, listener.CollectionChangedEventCount);

                // Some dummy code to make sure the previous listener is removed
                listener = new EventListener();
                GC.Collect();
                var type = listener.GetType();

                Assert.IsTrue(weakEventListener.IsSourceAlive);
                Assert.IsFalse(weakEventListener.IsTargetAlive);

                // Some dummy code to make sure the source stays in memory
                source.GetType();
            }