Exemplo n.º 1
0
        public void ShouldRegisterOnePublisher()
        {
            EventBroker broker = new EventBroker();
            EventSource1 publisher = new EventSource1();

            broker.RegisterPublisher("PublishedEvent1", publisher, "Event1");

            List<string> published = new List<string>(broker.RegisteredEvents);
            List<object> publishers = new List<object>(broker.GetPublishersFor("PublishedEvent1"));

            Assert.IsTrue(published.Contains("PublishedEvent1"));
            Assert.AreEqual(1, publishers.Count);
            Assert.AreSame(publisher, publishers[0]);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void ShouldRegisterOnePublisherAndOneSubscriber()
        {
            EventBroker broker = new EventBroker();
            EventSource1 publisher = new EventSource1();
            string publishedEventName = "MyEvent";
            EventHandler subscriber = delegate { };

            broker.RegisterPublisher(publishedEventName, publisher, "Event1");
            broker.RegisterSubscriber(publishedEventName, subscriber);
            
            List<string> published = new List<string>(broker.RegisteredEvents);
            List<object> publishers = new List<object>(broker.GetPublishersFor(publishedEventName));
            List<EventHandler> subscribers = new List<EventHandler>(broker.GetSubscribersFor(publishedEventName));

            Assert.AreEqual(1, published.Count);
            Assert.AreEqual(publishedEventName, published[0]);

            Assert.AreEqual(1, publishers.Count);
            Assert.AreSame(publisher, publishers[0]);

            Assert.AreEqual(1, subscribers.Count);
            Assert.AreSame(subscriber, subscribers[0]);
        }
Exemplo n.º 4
0
        public void ShouldRemovePublisherFromListOnUnregistration()
        {
            EventBroker broker = new EventBroker();
            EventSource1 publisher = new EventSource1();
            string publishedEventName = "MyEvent";
            broker.RegisterPublisher(publishedEventName, publisher, "Event1");

            broker.UnregisterPublisher(publishedEventName, publisher, "Event1");

            Assert.AreEqual(0, new List<object>(broker.GetPublishersFor(publishedEventName)).Count);
        }