コード例 #1
0
        public void Subscribe_will_not_add_same_object_twice()
        {
            var assignee = new SimpleSubscriber();
            var handler = new TestHandler();
            assignee.Subscribe(handler);
            assignee.Subscribe(handler);

            IEnumerable handlers = assignee.ResolveHandlersFor(typeof(TestMessage));

            Assert.That(handlers, Has.Member(handler));
            //Assert.That(handlers.Count(), Is.EqualTo(1));
        }
コード例 #2
0
        public void Subscribe_adds_it_to_the_source_so_it_can_be_resolved()
        {
            var assignee = new SimpleSubscriber();
            var handler = new TestHandler();
            assignee.Subscribe(handler);

            var handlers = assignee.ResolveHandlersFor(typeof(TestMessage));

            Assert.That(handlers, Has.Member(handler));
        }
コード例 #3
0
        public void Should_no_throw_if_no_dispatcher_found_and_set_to_ignore()
        {
            var assignee = new SimpleSubscriber();
            var handler = new TestHandler();
            var message = new TestMessage();
            var publisher = new Publisher(new PublisherSettings{IgnoreNoDispatcher = true},assignee, new[] { new SimpleDispatcher(new Rule(x => false)) });

            assignee.Subscribe(handler);

            Should.NotThrow(() => publisher.Publish(message));
        }
コード例 #4
0
        public void Unsubscribe_removes_it_from_source_so_it_could_be_resolved()
        {
            var assignee = new SimpleSubscriber();
            var handler = new TestHandler();
            assignee.Subscribe(handler);
            assignee.Unsubscribe(handler);

            var handlers = assignee.ResolveHandlersFor(typeof(TestMessage));

            Assert.That(handlers, Has.No.Member(handler));
        }
コード例 #5
0
        public void Should_not_throw_if_multiple_dispather_can_dispatch_a_message_and_set_to_ignore()
        {
            var assignee = new SimpleSubscriber();
            var dispatcher = new SimpleDispatcher();
            var handler = new TestHandler();
            var message = new TestMessage();
            var publisher = new Publisher(new PublisherSettings{IgnoreMultipleDispatcher = true},  assignee, new[] { dispatcher, dispatcher });

            assignee.Subscribe(handler);

            Should.NotThrow(() => publisher.Publish(message));
        }
コード例 #6
0
        public void Should_not_fail_if_onle_one_dispatcher_can_dispath_message()
        {
            var assignee = new SimpleSubscriber();
            var dispatcher = new SimpleDispatcher();
            var handler = new TestHandler();
            var message = new TestMessage();
            var publisher = new Publisher(assignee, new[] { dispatcher, new SimpleDispatcher(new Rule(x => false)) });

            assignee.Subscribe(handler);

            Should.NotThrow(() => publisher.Publish(message));
        }
コード例 #7
0
        public void Returns_same_object_for_different_handlers()
        {
            var assignee = new SimpleSubscriber();
            var handler = new MultiHandler();

            assignee.Subscribe(handler);

            var messageHandlers = assignee.ResolveHandlersFor(typeof(TestMessage));
            var anotherMessageHandlers = assignee.ResolveHandlersFor(typeof(AnotherMessage));

            CollectionAssert.AreEqual(messageHandlers, anotherMessageHandlers);
        }
コード例 #8
0
        public void Publish_will_send_the_message_to_listner()
        {
            var assignee = new SimpleSubscriber();
            var dispatcher = new SimpleDispatcher();
            var handler = new TestHandler();
            var message = new TestMessage();
            var publisher = new Publisher(assignee, new[] {dispatcher});

            assignee.Subscribe(handler);

            publisher.Publish(message);

            Assert.That(handler.TestMessage, Is.SameAs(message));
        }
コード例 #9
0
        public void Should_throw_if_multiple_dispather_can_dispatch_a_message()
        {
            var assignee = new SimpleSubscriber();
            var dispatcher = new SimpleDispatcher();
            var handler = new TestHandler();
            var message = new TestMessage();
            var publisher = new Publisher(assignee, new[] { dispatcher, dispatcher });

            assignee.Subscribe(handler);

            Should.Throw<InvalidOperationException>(() => publisher.Publish(message));
        }
コード例 #10
0
        public void Should_throw_if_no_dispatcher_found()
        {
            var assignee = new SimpleSubscriber();
            var handler = new TestHandler();
            var message = new TestMessage();
            var publisher = new Publisher(assignee, new[] { new SimpleDispatcher(new Rule(x => false)) });

            assignee.Subscribe(handler);

            Should.Throw<InvalidOperationException>(() => publisher.Publish(message));
        }