Ejemplo n.º 1
0
        public void RegisterHandlerMethod()
        {
            Publisher  p = new Publisher();
            Subscriber s = new Subscriber();

            this.testee.RegisterHandlerMethod(EventTopics.SimpleEvent, s, s.Handle, new Handlers.Publisher());
            this.testee.Register(p);

            p.CallSimpleEvent();

            Assert.IsTrue(s.Called, "event was not handled.");

            s.Reset();
            this.testee.RemoveSubscription(EventTopics.SimpleEvent, s, s.Handle);

            p.CallSimpleEvent();

            Assert.IsFalse(s.Called, "event should not have been handled.");
        }
        public void RegisterHandlerMethod()
        {
            Publisher p = new Publisher();
            Subscriber s = new Subscriber();

            this.testee.RegisterHandlerMethod(EventTopics.SimpleEvent, s, s.Handle, new Handlers.Publisher());
            this.testee.Register(p);

            p.CallSimpleEvent();

            Assert.IsTrue(s.Called, "event was not handled.");

            s.Reset();
            this.testee.RemoveSubscription(EventTopics.SimpleEvent, s, s.Handle);

            p.CallSimpleEvent();

            Assert.IsFalse(s.Called, "event should not have been handled.");
        }
Ejemplo n.º 3
0
        public void ExceptionHandlingMultipleException()
        {
            Publisher p = new Publisher();
            SubscriberThrowingException s1 = new SubscriberThrowingException();
            SubscriberThrowingException s2 = new SubscriberThrowingException();

            this.testee.Register(p);
            this.testee.Register(s1);
            this.testee.Register(s2);

            Assert.Throws <SubscriberThrowingException.TestException>(
                () => p.CallSimpleEvent());
        }
Ejemplo n.º 4
0
        public void DisposeUnregistersPublicationByProperty()
        {
            Publisher  p = new Publisher();
            Subscriber s = new Subscriber();

            this.testee.Register(p);
            this.testee.Register(s);

            this.testee.Dispose();

            Assert.Throws <NullReferenceException>(
                () => p.CallSimpleEvent(),
                "Should result in a null reference exception because the event should not be registered by the event topic anymore.");
        }
Ejemplo n.º 5
0
        public void SubscriptionsInCodeCanBeRemoved()
        {
            Publisher  p = new Publisher();
            Subscriber s = new Subscriber();

            this.testee.Register(p);
            this.testee.AddSubscription(EventTopics.SimpleEvent, s, s.SimpleEvent, new Handlers.Publisher());

            this.testee.RemoveSubscription(EventTopics.SimpleEvent, s, s.SimpleEvent);

            p.CallSimpleEvent();

            Assert.IsFalse(s.SimpleEventCalled);
        }
Ejemplo n.º 6
0
        public void GlobalPublicationMatcher()
        {
            var publicationMatcher = new TestPublicationMatcher();

            var publisher = new Publisher();
            var subscriber = new Subscriber();

            this.testee.Register(publisher);
            this.testee.Register(subscriber);

            this.testee.AddGlobalMatcher(publicationMatcher);

            publisher.CallSimpleEvent();

            subscriber.SimpleEventCalled.Should().BeFalse();
        }
Ejemplo n.º 7
0
        public void GlobalPublicationMatcher()
        {
            var publicationMatcher = new TestPublicationMatcher();

            var publisher  = new Publisher();
            var subscriber = new Subscriber();

            this.testee.Register(publisher);
            this.testee.Register(subscriber);

            this.testee.AddGlobalMatcher(publicationMatcher);

            publisher.CallSimpleEvent();

            subscriber.SimpleEventCalled.Should().BeFalse();
        }
Ejemplo n.º 8
0
        public void ExceptionHandlingWithExtensionHandlingException()
        {
            Publisher p = new Publisher();
            SubscriberThrowingException s = new SubscriberThrowingException();

            var exceptionHandlingExtension = new ExceptionHandlingExtension();

            this.testee.AddExtension(exceptionHandlingExtension);

            this.testee.Register(p);
            this.testee.Register(s);

            p.CallSimpleEvent();

            exceptionHandlingExtension.HandledException
            .Should().BeOfType <SubscriberThrowingException.TestException>();
        }
        public void ExceptionHandlingMultipleException()
        {
            Publisher p = new Publisher();
            SubscriberThrowingException s1 = new SubscriberThrowingException();
            SubscriberThrowingException s2 = new SubscriberThrowingException();

            this.testee.Register(p);
            this.testee.Register(s1);
            this.testee.Register(s2);

            Assert.Throws<SubscriberThrowingException.TestException>(
                () => p.CallSimpleEvent());
        }
        public void ExceptionHandlingWithExtensionHandlingException()
        {
            Publisher p = new Publisher();
            SubscriberThrowingException s = new SubscriberThrowingException();

            var exceptionHandlingExtension = new ExceptionHandlingExtension();
            this.testee.AddExtension(exceptionHandlingExtension);

            this.testee.Register(p);
            this.testee.Register(s);

            p.CallSimpleEvent();

            exceptionHandlingExtension.HandledException
                .Should().BeOfType<SubscriberThrowingException.TestException>();
        }
Ejemplo n.º 11
0
        public void DisposeUnregistersPublicationByProperty()
        {
            Publisher p = new Publisher();
            Subscriber s = new Subscriber();

            this.testee.Register(p);
            this.testee.Register(s);

            this.testee.Dispose();

            Assert.Throws<NullReferenceException>(
                () => p.CallSimpleEvent(),
                "Should result in a null reference exception because the event should not be registered by the event topic anymore.");
        }
Ejemplo n.º 12
0
        public void SubscriptionsInCodeCanBeRemoved()
        {
            Publisher p = new Publisher();
            Subscriber s = new Subscriber();

            this.testee.Register(p);
            this.testee.AddSubscription(EventTopics.SimpleEvent, s, s.SimpleEvent, new Handlers.Publisher());

            this.testee.RemoveSubscription(EventTopics.SimpleEvent, s, s.SimpleEvent);

            p.CallSimpleEvent();

            Assert.IsFalse(s.SimpleEventCalled);
        }
        public void ExceptionHandling()
        {
            try
            {
                Publisher p = new Publisher();
                SubscriberThrowingException s = new SubscriberThrowingException();

                this.testee.Register(p);
                this.testee.Register(s);

                p.CallSimpleEvent();

                Assert.Fail("must not be reached.");
            }
            catch (EventTopicException e)
            {
                Assert.IsTrue(e.InnerException is SubscriberThrowingException.TestException);
            }
        }