コード例 #1
0
        public void CanSubscribeMultipleTargets()
        {
            var bus = new DirectDispatchMessageBus();

            var target1 = new SingleSubscriber();
            var target2 = new SingleSubscriber();
            bus.Subscribe(target1);
            bus.Subscribe(target2);

            var message = new TestMessage();
            bus.Publish(message);

            Assert.That(target1.LastMessage, Is.SameAs(message));
            Assert.That(target2.LastMessage, Is.SameAs(message));
        }
コード例 #2
0
        public void CollectedTargetIsUnsubscribed()
        {
            var bus = new DirectDispatchMessageBus();

            bus.Subscribe(new SingleSubscriber());
            GC.Collect();

            var message = new TestMessage();
            bus.Publish(message);

            Assert.That(message.LastReceiver, Is.Null);
        }
コード例 #3
0
        public void CanUnsubscribe()
        {
            var bus = new DirectDispatchMessageBus();

            var target = new SingleSubscriber();
            bus.Subscribe(target);
            bus.Unsubscribe(target);

            var message = new TestMessage();
            bus.Publish(message);

            Assert.That(message.LastReceiver, Is.Null);
        }
コード例 #4
0
        public void SameTargetCanOnlySubscribeOnce()
        {
            var bus = new DirectDispatchMessageBus();

            var target = new SingleSubscriber();
            bus.Subscribe(target);
            bus.Subscribe(target);

            bus.Publish<TestMessage>();

            Assert.That(target.ReceivedMessages, Is.EqualTo(1));
        }
コード例 #5
0
        public void CanSubscribeWithoutHandlerMethod()
        {
            var bus = new DirectDispatchMessageBus();

            Assert.DoesNotThrow(() => bus.Subscribe(new string('s', 10)));
        }
コード例 #6
0
        public void MessagesAreHandledInPolymorphicFashion()
        {
            var bus = new DirectDispatchMessageBus();

            var target = new PolySubscriber();
            bus.Subscribe(target);

            bus.Publish<DerivedTestMessage>();

            Assert.That(target.MessageHandleCount, Is.EqualTo(2));
            Assert.That(target.HandledMessageTypes.Contains(typeof(TestMessage)));
            Assert.That(target.HandledMessageTypes.Contains(typeof(DerivedTestMessage)));
        }
コード例 #7
0
        public void CanSubscribe()
        {
            var bus = new DirectDispatchMessageBus();

            Assert.DoesNotThrow(() => bus.Subscribe(new SingleSubscriber()));
        }