Beispiel #1
0
        public void ShouldNotCallSubscriberAfterRemoval()
        {
            PublishedEvent pe = new PublishedEvent();
            EventSource1 publisher = new EventSource1();
            pe.AddPublisher(publisher, "Event1");
            int numberOfSubscriberCalls = 0;
            EventHandler subscriber = delegate { ++numberOfSubscriberCalls; };
            pe.AddSubscriber(subscriber);

            publisher.FireEvent1();

            pe.RemoveSubscriber(subscriber);
            publisher.FireEvent1();

            Assert.AreEqual(1, numberOfSubscriberCalls);
        }
        public void ShouldNotCallSubscriberAfterRemoval()
        {
            PublishedEvent pe        = new PublishedEvent();
            EventSource1   publisher = new EventSource1();

            pe.AddPublisher(publisher, "Event1");
            int          numberOfSubscriberCalls = 0;
            EventHandler subscriber = delegate { ++numberOfSubscriberCalls; };

            pe.AddSubscriber(subscriber);

            publisher.FireEvent1();

            pe.RemoveSubscriber(subscriber);
            publisher.FireEvent1();

            Assert.AreEqual(1, numberOfSubscriberCalls);
        }
Beispiel #3
0
        public void ShouldCallSubscriberWhenPublisherFiresEvent()
        {
            PublishedEvent pe = new PublishedEvent();
            EventSource1 publisher = new EventSource1();
            pe.AddPublisher(publisher, "Event1");
            bool subscriberCalled = false;
            EventHandler subscriber = delegate { subscriberCalled = true; };
            pe.AddSubscriber(subscriber);

            publisher.FireEvent1();

            Assert.IsTrue(subscriberCalled);
        }
        public void ShouldCallSubscriberWhenPublisherFiresEvent()
        {
            PublishedEvent pe        = new PublishedEvent();
            EventSource1   publisher = new EventSource1();

            pe.AddPublisher(publisher, "Event1");
            bool         subscriberCalled = false;
            EventHandler subscriber       = delegate { subscriberCalled = true; };

            pe.AddSubscriber(subscriber);

            publisher.FireEvent1();

            Assert.IsTrue(subscriberCalled);
        }
        public void ShouldCallSubscriberWhenPublisherFiresEvent()
        {
            EventBroker  broker             = new EventBroker();
            EventSource1 publisher          = new EventSource1();
            string       publishedEventName = "MyEvent";
            bool         subscriberFired    = false;
            EventHandler subscriber         = delegate { subscriberFired = true; };

            broker.RegisterPublisher(publishedEventName, publisher, "Event1");
            broker.RegisterSubscriber(publishedEventName, subscriber);

            publisher.FireEvent1();

            Assert.IsTrue(subscriberFired);
        }
Beispiel #6
0
        public void ShouldMulticastEventsToMultipleSubscribers()
        {
            PublishedEvent pe = new PublishedEvent();
            EventSource1 publisher = new EventSource1();
            pe.AddPublisher(publisher, "Event1");
            bool subscriber1Called = false;
            EventHandler subscriber1 = delegate { subscriber1Called = true; };
            bool subscriber2Called = false;
            EventHandler subscriber2 = delegate { subscriber2Called = true; };
            pe.AddSubscriber(subscriber1);
            pe.AddSubscriber(subscriber2);

            publisher.FireEvent1();

            Assert.IsTrue(subscriber1Called);
            Assert.IsTrue(subscriber2Called);
        }
        public void ShouldMulticastEventsToMultipleSubscribers()
        {
            PublishedEvent pe        = new PublishedEvent();
            EventSource1   publisher = new EventSource1();

            pe.AddPublisher(publisher, "Event1");
            bool         subscriber1Called = false;
            EventHandler subscriber1       = delegate { subscriber1Called = true; };
            bool         subscriber2Called = false;
            EventHandler subscriber2       = delegate { subscriber2Called = true; };

            pe.AddSubscriber(subscriber1);
            pe.AddSubscriber(subscriber2);

            publisher.FireEvent1();

            Assert.IsTrue(subscriber1Called);
            Assert.IsTrue(subscriber2Called);
        }
        public void ShouldCallSubscriberWhenPublisherFiresEvent()
        {
            EventBroker broker = new EventBroker();
            EventSource1 publisher = new EventSource1();
            string publishedEventName = "MyEvent";
            bool subscriberFired = false;
            EventHandler subscriber = delegate { subscriberFired = true;  };

            broker.RegisterPublisher(publishedEventName, publisher, "Event1");
            broker.RegisterSubscriber(publishedEventName, subscriber);

            publisher.FireEvent1();

            Assert.IsTrue(subscriberFired);
        }