public void TestSubscribingDuringPublishing() { IEventHub hub = EventHub; Box <int> box = new Box <int>(0); Assert.IsTrue(hub.Subscribe <EventHubTests, IEventHub>(this, SubInsideThisMethod)); Assert.DoesNotThrow(() => hub.Publish(hub)); hub.Publish(box); hub.Unsubscribe <EventHubTests, IEventHub>(this); hub.Unsubscribe <EventHubTests, Box <int> >(this); Assert.AreEqual(1, box.Value); }
public void TestSubUnsubUsingMethods() { IEventHub hub = EventHub; Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox)); Assert.IsTrue(hub.Unsubscribe <EventHubTests, Box <int> >(this)); }
public void TestSubUnsubUsingLambdas() { IEventHub hub = EventHub; Box <int> box = new Box <int>(0); Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, b => b.Value++)); Assert.IsTrue(hub.Unsubscribe <EventHubTests, Box <int> >(this)); }
public void TestPubMultiSubUsingLambdas() { IEventHub hub = EventHub; Box <int> box = new Box <int>(0); Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, b => b.Value++)); Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, b => b.Value++)); hub.Publish(box); hub.Unsubscribe <EventHubTests, Box <int> >(this); Assert.AreEqual(2, box.Value); }
public void TestPubMultiSubUsingMethods() { IEventHub hub = EventHub; Box <int> box = new Box <int>(0); Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox)); Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox2)); hub.Publish(box); hub.Unsubscribe <EventHubTests, Box <int> >(this); Assert.AreEqual(2, box.Value); }
public void TestNoSubUnsubUsingMethods() { IEventHub hub = EventHub; Assert.IsFalse(hub.Unsubscribe <EventHubTests, Box <int> >(this)); }
private void UnsubInsideThisMethod(IEventHub hub) { hub.Unsubscribe <EventHubTests, IEventHub>(this); hub.Unsubscribe <EventHubTests, Box <int> >(this); }
public void Unsubscribe(Action <T> action) { _hub.Unsubscribe(action); }