Exemplo n.º 1
0
        public async Task ShouldDirectMessageToType()
        {
            var messenger = new Messenger();

            var m1 = new MessageSubscriberMock1();

            messenger.Subscribe(m1);

            var m2 = new MessageSubscriberMock2();

            messenger.Subscribe(m2);

            var message1 = new MessageDefinition1();
            await messenger.PublishAsync(message1);

            Assert.AreEqual(message1, m1.Message);
            Assert.AreEqual(message1, m2.Message);

            var message2 = new MessageDefinition1();
            await messenger.PublishAsync(message2,
                                         recipientType : typeof(MessageSubscriberMock1));

            Assert.AreEqual(message2, m1.Message);
            Assert.AreEqual(message1, m2.Message);
        }
Exemplo n.º 2
0
        public async Task ShouldRegisterAndResolveTypes()
        {
            var messenger = new Messenger();
            var m1        = new MessageSubscriberMock1();

            messenger.Subscribe(m1);

            var message1 = new MessageDefinition1();
            await messenger.PublishAsync(message1);

            Assert.AreEqual(message1, m1.Message);

            messenger.Unsubscribe(m1);

            var message2 = new MessageDefinition1();
            await messenger.PublishAsync(message2);

            Assert.AreEqual(message1, m1.Message,
                            "Message should be the same as before the unsubscription.");
        }