Ejemplo n.º 1
0
        public void PublishAllEventsAndSubscribeToSome()
        {
            IEventRegistry registry = new EventRegistry();
            SimpleClient   client   = new SimpleClient("PublishAllEventsAndSubscribeToSome");

            registry.PublishEvents(client);
            EventSubscriber      sub  = new EventSubscriber();
            OtherEventSubscriber sub2 = new OtherEventSubscriber();

            Assert.IsFalse(sub.EventRaised, "Event raised");
            Assert.IsFalse(sub2.EventRaised, "Event raised");

            client.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event raised");

            client.ClientMethodThatTriggersEvent3();
            Assert.IsFalse(sub2.EventRaised, "Event raised");

            registry.Subscribe(sub);
            registry.Subscribe(sub2);
            client.ClientMethodThatTriggersEvent();
            client.ClientMethodThatTriggersEvent3();
            Assert.IsTrue(sub.EventRaised, "Event Not Raised");
            Assert.IsTrue(sub2.EventRaised, "Event Not Raised");
        }
Ejemplo n.º 2
0
        public void PublishAllEventsSubscribeToNamedEvents()
        {
            IEventRegistry registry = new EventRegistry();
            SimpleClient   client   = new SimpleClient("PublishAllEvents");
            SimpleClient2  client2  = new SimpleClient2();

            registry.PublishEvents(client);
            registry.PublishEvents(client2);

            EventSubscriber sub  = new EventSubscriber();
            EventSubscriber sub2 = new EventSubscriber();

            Assert.IsFalse(sub.EventRaised, "Event raised");
            Assert.IsFalse(sub2.EventRaised, "Event raised");

            client.ClientMethodThatTriggersEvent();
            client2.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event raised");
            Assert.IsFalse(sub2.EventRaised, "Event raised");

            registry.Subscribe(sub, typeof(SimpleClient));
            registry.Subscribe(sub2, typeof(SimpleClient2));

            client.ClientMethodThatTriggersEvent();
            Assert.IsTrue(sub.EventRaised, "Event Not Raised");
            Assert.IsFalse(sub2.EventRaised, "Event raised");

            client2.ClientMethodThatTriggersEvent();
            Assert.IsTrue(sub.EventRaised, "Event Not Raised");
            Assert.IsTrue(sub2.EventRaised, "Event Not Raised");
        }
Ejemplo n.º 3
0
        public void NoPublishers()
        {
            IEventRegistry   registry = new EventRegistry();
            SimpleClient     client   = new SimpleClient("PublishAllEvents");
            SimpleSubscriber sub      = new SimpleSubscriber();

            Assert.IsFalse(sub.EventRaised, "Event raised");

            client.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event raised");

            registry.Subscribe(sub);
            client.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event Raised");
        }
Ejemplo n.º 4
0
        public void NoValidEventHandlersOrEventsToSubscribeto()
        {
            IEventRegistry    registry = new EventRegistry();
            SimpleClient      client   = new SimpleClient("PublishAllEvents");
            NoEventSubscriber sub      = new NoEventSubscriber();

            registry.PublishEvents(client);

            Assert.IsFalse(sub.EventRaised, "Event raised");
            client.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event raised");

            registry.Subscribe(sub);
            client.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event Raised");
        }
Ejemplo n.º 5
0
        public void RespectsInheritance()
        {
            SimpleClient source = new SimpleClient("foo");

            IEventRegistry registry = new EventRegistry();

            registry.PublishEvents(source);

            EventSubscriber sub = new EventSubscriber();

            Assert.IsFalse(sub.EventRaised, "Event raised");

            source.ClientMethodThatTriggersEvent();
            Assert.IsFalse(sub.EventRaised, "Event raised");

            registry.Subscribe(sub, typeof(ISimpleClient));
            source.ClientMethodThatTriggersEvent();
            Assert.IsTrue(sub.EventRaised, "Event Not Raised");
        }
Ejemplo n.º 6
0
        public void PublishAllEventsMultipleSubscribersAndUnsubscribe()
        {
            IEventRegistry registry = new EventRegistry();
            SimpleClient   client   = new SimpleClient("PublishAllEvents");

            registry.PublishEvents(client);
            EventSubscriber sub  = new EventSubscriber();
            EventSubscriber sub2 = new EventSubscriber();

            registry.Subscribe(sub);
            registry.Subscribe(sub2);
            client.ClientMethodThatTriggersEvent();
            Assert.IsTrue(sub.EventRaised, "Event Not Raised");
            Assert.IsTrue(sub2.EventRaised, "Event Not Raised");
            Assert.AreEqual(1, sub.EventCount);
            Assert.AreEqual(1, sub2.EventCount);

            registry.Unsubscribe(sub2);
            client.ClientMethodThatTriggersEvent();
            Assert.AreEqual(2, sub.EventCount);
            Assert.AreEqual(1, sub2.EventCount);
        }
Ejemplo n.º 7
0
		public void PublishAllEventsAndSubscribeToSome()
		{
			IEventRegistry registry = new EventRegistry();
			SimpleClient client = new SimpleClient("PublishAllEventsAndSubscribeToSome");
			registry.PublishEvents(client);
			EventSubscriber sub = new EventSubscriber();
			OtherEventSubscriber sub2 = new OtherEventSubscriber();
			Assert.IsFalse(sub.EventRaised, "Event raised");
			Assert.IsFalse(sub2.EventRaised, "Event raised");

			client.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event raised");

			client.ClientMethodThatTriggersEvent3();
			Assert.IsFalse(sub2.EventRaised, "Event raised");

			registry.Subscribe(sub);
			registry.Subscribe(sub2);
			client.ClientMethodThatTriggersEvent();
			client.ClientMethodThatTriggersEvent3();
			Assert.IsTrue(sub.EventRaised, "Event Not Raised");
			Assert.IsTrue(sub2.EventRaised, "Event Not Raised");
		}
Ejemplo n.º 8
0
		public void NoPublishers()
		{
			IEventRegistry registry = new EventRegistry();
			SimpleClient client = new SimpleClient("PublishAllEvents");
			SimpleSubscriber sub = new SimpleSubscriber();
			Assert.IsFalse(sub.EventRaised, "Event raised");

			client.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event raised");

			registry.Subscribe(sub);
			client.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event Raised");
		}
Ejemplo n.º 9
0
		public void NoValidEventHandlersOrEventsToSubscribeto()
		{
			IEventRegistry registry = new EventRegistry();
			SimpleClient client = new SimpleClient("PublishAllEvents");
			NoEventSubscriber sub = new NoEventSubscriber();
			registry.PublishEvents(client);

			Assert.IsFalse(sub.EventRaised, "Event raised");
			client.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event raised");

			registry.Subscribe(sub);
			client.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event Raised");
		}
Ejemplo n.º 10
0
		public void PublishAllEventsSubscribeToNamedEvents()
		{
			IEventRegistry registry = new EventRegistry();
			SimpleClient client = new SimpleClient("PublishAllEvents");
			SimpleClient2 client2 = new SimpleClient2();

			registry.PublishEvents(client);
			registry.PublishEvents(client2);

			EventSubscriber sub = new EventSubscriber();
			EventSubscriber sub2 = new EventSubscriber();

			Assert.IsFalse(sub.EventRaised, "Event raised");
			Assert.IsFalse(sub2.EventRaised, "Event raised");

			client.ClientMethodThatTriggersEvent();
			client2.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event raised");
			Assert.IsFalse(sub2.EventRaised, "Event raised");

			registry.Subscribe(sub, typeof (SimpleClient));
			registry.Subscribe(sub2, typeof (SimpleClient2));

			client.ClientMethodThatTriggersEvent();
			Assert.IsTrue(sub.EventRaised, "Event Not Raised");
			Assert.IsFalse(sub2.EventRaised, "Event raised");

			client2.ClientMethodThatTriggersEvent();
			Assert.IsTrue(sub.EventRaised, "Event Not Raised");
			Assert.IsTrue(sub2.EventRaised, "Event Not Raised");
		}
Ejemplo n.º 11
0
        public void PublishAllEventsMultipleSubscribersAndUnsubscribe()
        {
            IEventRegistry registry = new EventRegistry();
            SimpleClient client = new SimpleClient("PublishAllEvents");
            registry.PublishEvents(client);
            EventSubscriber sub = new EventSubscriber();
            EventSubscriber sub2 = new EventSubscriber();
            registry.Subscribe(sub);
            registry.Subscribe(sub2);
            client.ClientMethodThatTriggersEvent();
            Assert.IsTrue(sub.EventRaised, "Event Not Raised");
            Assert.IsTrue(sub2.EventRaised, "Event Not Raised");
            Assert.AreEqual(1, sub.EventCount);
            Assert.AreEqual(1, sub2.EventCount);

            registry.Unsubscribe(sub2);
            client.ClientMethodThatTriggersEvent();
            Assert.AreEqual(2, sub.EventCount);
            Assert.AreEqual(1, sub2.EventCount);
        }
Ejemplo n.º 12
0
		public void RespectsInheritance()
		{
			SimpleClient source = new SimpleClient("foo");

			IEventRegistry registry = new EventRegistry();
			registry.PublishEvents(source);

			EventSubscriber sub = new EventSubscriber();
			Assert.IsFalse(sub.EventRaised, "Event raised");

			source.ClientMethodThatTriggersEvent();
			Assert.IsFalse(sub.EventRaised, "Event raised");

			registry.Subscribe(sub, typeof(ISimpleClient));
			source.ClientMethodThatTriggersEvent();
			Assert.IsTrue(sub.EventRaised, "Event Not Raised");
		}