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); }
private void SimpleEvent(int runNumber) { EventBroker eventBroker = new EventBroker(); var p = new Publisher(); var s = new Subscriber(); eventBroker.Register(p); eventBroker.Register(s); this.Run( p.FireEvent, runNumber + " simple event", 0); }
private void FalseMatcher(int runNumber) { EventBroker eventBroker = new EventBroker(); eventBroker.AddGlobalMatcher(new Matcher(false)); var p = new Publisher(); var s = new Subscriber(); eventBroker.Register(p); eventBroker.Register(s); this.Run( p.FireEvent, runNumber + " false matcher", 0); }
public void SeveralHandlers() { EventBroker eventBroker = new EventBroker(); Publisher p = new Publisher(); Subscriber s1 = new Subscriber(); Subscriber s2 = new Subscriber(); eventBroker.Register(p); eventBroker.Register(s1); eventBroker.Register(s2); CancelEventArgs e = new CancelEventArgs(false); p.Fire(e); Assert.AreEqual(1, s1.NumberOfHandledEvents, "s1 was not called"); Assert.AreEqual(0, s2.NumberOfHandledEvents, "s2 was called"); }
public void Restrict() { EventBroker eventBroker = new EventBroker(); Publisher p = new Publisher(); Subscriber s = new Subscriber(); eventBroker.Register(p); eventBroker.Register(s); CancelEventArgs e = new CancelEventArgs(false); p.Fire(e); Assert.AreEqual(1, s.NumberOfHandledEvents, "should be handled."); p.Fire(e); Assert.AreEqual(1, s.NumberOfHandledEvents, "should not be handled."); }
private void Subscribers(int runNumber, int numberOfSubscribersInThisRun) { EventBroker eventBroker = new EventBroker(); var p = new Publisher(); var subscribers = new Subscriber[numberOfSubscribersInThisRun]; for (int i = 0; i < numberOfSubscribersInThisRun; i++) { subscribers[i] = new Subscriber(); eventBroker.Register(subscribers[i]); } eventBroker.Register(p); this.Run( p.FireEvent, runNumber + " number of subscribers " + numberOfSubscribersInThisRun, -9 * this.numberOfEvents / 10); }
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); }