Example #1
0
        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);
        }
Example #2
0
        public void TestSubUnsubUsingMethods()
        {
            IEventHub hub = EventHub;

            Assert.IsTrue(hub.Subscribe <EventHubTests, Box <int> >(this, IncrementBox));
            Assert.IsTrue(hub.Unsubscribe <EventHubTests, Box <int> >(this));
        }
Example #3
0
        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));
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        public void TestNoSubUnsubUsingMethods()
        {
            IEventHub hub = EventHub;

            Assert.IsFalse(hub.Unsubscribe <EventHubTests, Box <int> >(this));
        }
Example #7
0
 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);
 }