Пример #1
0
 public void IsAliveTest()
 {
     var classWithEvent = new ClassWithEvent();
     var subscriber = new Subscriber(classWithEvent);
     classWithEvent.RaiseEvent();
     Assert.AreEqual(1, subscriber.count);
     var weakReference = new WeakReference(subscriber);
     Assert.IsTrue(weakReference.IsAlive, "Assert is alive before GC");
     subscriber = null;
     GC.Collect();
     Assert.IsFalse(weakReference.IsAlive, "Assert collected");
 }
Пример #2
0
 public Subscriber(ClassWithEvent classWithEvent)
 {
     classWithEvent.Event += (sender, args) => count++;
 }