public void MultiplePublisherMultipleSubscriber() { EventBroker eb = new EventBroker(); Subscriber.Count = 0; Publisher p1 = new Publisher(); Publisher p2 = new Publisher(); Subscriber s1 = new Subscriber(); Subscriber s2 = new Subscriber(); Subscriber s3 = new Subscriber(); eb.Register(p1); eb.Register(p2); eb.Register(s1); eb.Register(s2); eb.Register(s3); p1.CallCount(); p2.CallCount(); eb.Unregister(p1); eb.Unregister(p2); eb.Unregister(s1); eb.Unregister(s2); eb.Unregister(s3); Assert.AreEqual(6, Subscriber.Count); }
public void PublisherWithoutSubscriber() { EventBroker eb = new EventBroker(); Publisher p = new Publisher(); Subscriber.Count = 0; eb.Register(p); p.CallCount(); eb.Unregister(p); Assert.AreEqual(0, Subscriber.Count); }
public void FreedSubscriber() { Publisher p = new Publisher(); Subscriber s1 = new Subscriber(); Subscriber s2 = new Subscriber(); this.testee.Register(p); this.testee.Register(s1); this.testee.Register(s2); // ReSharper disable RedundantAssignment s1 = null; // kill reference to s1 // ReSharper restore RedundantAssignment GC.Collect(); // breaks up the weak reference to the subscriber p.CallCount(); Assert.AreEqual(1, Subscriber.Count); Assert.Greater(s2.ThreadId, -10); // just some stupid code to prevent s2 from being collected }