Exemplo n.º 1
0
        public void ManyPublishersOneSubscriber()
        {
            using (var kernel = new StandardKernel(new MessageBrokerModule()))
            {
                PublisherMock pub1 = kernel.Get <PublisherMock>();
                PublisherMock pub2 = kernel.Get <PublisherMock>();
                Assert.That(pub1, Is.Not.Null);
                Assert.That(pub2, Is.Not.Null);

                SubscriberMock sub = kernel.Get <SubscriberMock>();
                Assert.That(sub, Is.Not.Null);

                Assert.That(pub1.HasListeners);
                Assert.That(pub2.HasListeners);
                Assert.That(sub.LastMessage, Is.Null);

                pub1.SendMessage("Hello, world!");
                Assert.That(sub.LastMessage, Is.EqualTo("Hello, world!"));

                sub.LastMessage = null;
                Assert.That(sub.LastMessage, Is.Null);

                pub2.SendMessage("Hello, world!");
                Assert.That(sub.LastMessage, Is.EqualTo("Hello, world!"));
            }
        }
Exemplo n.º 2
0
        public void ClosingChannelUnbindsPublisherEventsFromChannel()
        {
            using (var kernel = new StandardKernel(new MessageBrokerModule()))
            {
                PublisherMock pub = kernel.Get <PublisherMock>();
                Assert.That(pub, Is.Not.Null);

                SubscriberMock sub = kernel.Get <SubscriberMock>();
                Assert.That(sub, Is.Not.Null);

                Assert.That(sub.LastMessage, Is.Null);

                var messageBroker = kernel.Components.Get <IMessageBroker>();
                messageBroker.CloseChannel("message://PublisherMock/MessageReceived");
                Assert.That(pub.HasListeners, Is.False);

                pub.SendMessage("Hello, world!");
                Assert.That(sub.LastMessage, Is.Null);
            }
        }
Exemplo n.º 3
0
        public void DisabledChannelsDoNotUnbindButEventsAreNotSent()
        {
            using (var kernel = new StandardKernel(new MessageBrokerModule()))
            {
                PublisherMock pub = kernel.Get <PublisherMock>();
                Assert.That(pub, Is.Not.Null);

                SubscriberMock sub = kernel.Get <SubscriberMock>();
                Assert.That(sub, Is.Not.Null);

                Assert.That(sub.LastMessage, Is.Null);

                var messageBroker = kernel.Components.Get <IMessageBroker>();
                messageBroker.DisableChannel("message://PublisherMock/MessageReceived");
                Assert.That(pub.HasListeners);

                pub.SendMessage("Hello, world!");
                Assert.That(sub.LastMessage, Is.Null);
            }
        }