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");
        }
        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");
        }
        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");
        }
        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");
        }
        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);
        }
		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");
		}
		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");
		}
		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");
		}
        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);
        }
示例#10
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");
		}