Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public void TestNoSubUnsubUsingMethods()
        {
            IEventHub hub = EventHub;

            Assert.IsFalse(hub.Unsubscribe <EventHubTests, Box <int> >(this));
        }
Exemplo n.º 7
0
 private void UnsubInsideThisMethod(IEventHub hub)
 {
     hub.Unsubscribe <EventHubTests, IEventHub>(this);
     hub.Unsubscribe <EventHubTests, Box <int> >(this);
 }
Exemplo n.º 8
0
 public void Unsubscribe(Action <T> action)
 {
     _hub.Unsubscribe(action);
 }