Esempio n. 1
0
        public void CanHaveMultipleSubscribersAndRaiseCustomEvent()
        {
            var     customEvent = new TestableEventBase();
            Payload payload     = new Payload();

            object[] received1          = null;
            object[] received2          = null;
            var      eventSubscription1 = new MockEventSubscription();

            eventSubscription1.GetPublishActionReturnValue = delegate(object[] args) { received1 = args; };
            var eventSubscription2 = new MockEventSubscription();

            eventSubscription2.GetPublishActionReturnValue = delegate(object[] args) { received2 = args; };

            customEvent.Subscribe(eventSubscription1);
            customEvent.Subscribe(eventSubscription2);

            customEvent.Publish(payload);

            Assert.AreEqual(1, received1.Length);
            Assert.AreSame(received1[0], payload);

            Assert.AreEqual(1, received2.Length);
            Assert.AreSame(received2[0], payload);
        }
Esempio n. 2
0
		public void WhenEventSubscriptionActionIsNullPruneItFromList()
		{
			var eventBase = new TestableEventBase();
			var eventSubscription = new MockEventSubscription { GetPublishActionReturnValue = null };
			var token = eventBase.Subscribe(eventSubscription);
			eventBase.Publish();
			Assert.False(eventBase.Contains(token));
		}
Esempio n. 3
0
		public void CanPublishSimpleEvents()
		{
			var eventBase = new TestableEventBase();
			var eventSubscription = new MockEventSubscription();
			bool eventPublished = false;
			eventSubscription.GetPublishActionReturnValue = delegate { eventPublished = true; };
			eventBase.Subscribe(eventSubscription);
			eventBase.Publish();
			Assert.True(eventSubscription.GetPublishActionCalled);
			Assert.True(eventPublished);
		}
Esempio n. 4
0
        public void CanHaveMultipleSubscribersAndRaiseCustomEvent()
        {
            var customEvent = new TestableEventBase();
            Payload payload = new Payload();
            object[] received1 = null;
            object[] received2 = null;
            var eventSubscription1 = new MockEventSubscription();
            eventSubscription1.GetPublishActionReturnValue = delegate(object[] args) { received1 = args; };
            var eventSubscription2 = new MockEventSubscription();
            eventSubscription2.GetPublishActionReturnValue = delegate(object[] args) { received2 = args; };

            customEvent.Subscribe(eventSubscription1);
            customEvent.Subscribe(eventSubscription2);

            customEvent.Publish(payload);

            Assert.AreEqual(1, received1.Length);
            Assert.AreSame(received1[0], payload);

            Assert.AreEqual(1, received2.Length);
            Assert.AreSame(received2[0], payload);
        }
Esempio n. 5
0
        public void WhenEventSubscriptionActionIsNullPruneItFromList()
        {
            var eventBase = new TestableEventBase();

            var eventSubscription = new MockEventSubscription();
            eventSubscription.GetPublishActionReturnValue = null;

            var token = eventBase.Subscribe(eventSubscription);

            eventBase.Publish();

            Assert.IsFalse(eventBase.Contains(token));
        }
Esempio n. 6
0
        public void ShouldSubscribeAndUnsubscribe()
        {
            var eventBase = new TestableEventBase();

            var eventSubscription = new MockEventSubscription();
            eventBase.Subscribe(eventSubscription);

            Assert.IsNotNull(eventSubscription.SubscriptionToken);
            Assert.IsTrue(eventBase.Contains(eventSubscription.SubscriptionToken));

            eventBase.Unsubscribe(eventSubscription.SubscriptionToken);

            Assert.IsFalse(eventBase.Contains(eventSubscription.SubscriptionToken));
        }
Esempio n. 7
0
		public void ShouldSubscribeAndUnsubscribe()
		{
			var eventBase = new TestableEventBase();

			var eventSubscription = new MockEventSubscription();
			eventBase.Subscribe(eventSubscription);

			Assert.NotNull(eventSubscription.SubscriptionToken);
			Assert.True(eventBase.Contains(eventSubscription.SubscriptionToken));

			eventBase.Unsubscribe(eventSubscription.SubscriptionToken);

			Assert.False(eventBase.Contains(eventSubscription.SubscriptionToken));
		}
Esempio n. 8
0
        public void CanPublishSimpleEvents()
        {
            var eventBase = new TestableEventBase();
            var eventSubscription = new MockEventSubscription();
            bool eventPublished = false;
            eventSubscription.GetPublishActionReturnValue = delegate
                                                                {
                                                                    eventPublished = true;
                                                                };
            eventBase.Subscribe(eventSubscription);

            eventBase.Publish();

            Assert.IsTrue(eventSubscription.GetPublishActionCalled);
            Assert.IsTrue(eventPublished);
        }