コード例 #1
0
ファイル: StalkerTest.cs プロジェクト: DamianReeves/Stalker
 public void WatchedObjectsCanBeGarbageCollected()
 {
     var watchedItem = new WatchedItem();
     var weakReference = new WeakReference(watchedItem);
     var stalker = new Stalker();
     stalker.Watch(watchedItem);
     watchedItem = null;
     GC.Collect();
     weakReference.ShouldHave().Properties(x=>x.IsAlive).EqualTo(new {IsAlive=false});
 }
コード例 #2
0
        public void SubscripingToEventDoesNotKeepItAlive()
        {
            var sink = new EventSink();
            var mockListener = new Mock<IEventListener>();
            mockListener.Setup(l => l.OnGenericEvent()).Verifiable();

            EventManager.SubscribeTo<IEventListener, EventArgs>(
                h => sink.GenericEvent += h,
                h => sink.GenericEvent -= h,
                mockListener.Object,
                (l, args) => l.OnGenericEvent()
            );

            var weakReference = new WeakReference(sink);
            sink = null;
            GC.Collect();
            weakReference.ShouldHave().Properties(x=>x.IsAlive).EqualTo(new{IsAlive=false});
        }