public void SubscriberReceivesBroadcastedMessage()
        {
            var listener = new ListenerSpy();

            receiver.SubscribeToMessage("AMessage", listener.Method);

            dispatcher.Broadcast("AMessage");

            Assert.IsTrue(listener.HasReceivedMessage);
        }
        public void UnsubscribeListener()
        {
            var listener = new ListenerSpy();

            receiver.SubscribeToMessage("AMessage", listener.Method);
            receiver.UnsubscribeFromMessage("AMessage");

            dispatcher.Broadcast("AMessage");

            Assert.IsFalse(listener.HasReceivedMessage);
        }
        public void BroadcastWithDataPassesOnDataObject()
        {
            var listener = new ListenerSpy();

            receiver.SubscribeToMessage("AMessage", listener.Method);
            var data = new DataDummy();

            dispatcher.BroadcastWithData("AMessage", data);

            Assert.AreSame(data, listener.ReceivedData);
        }
        public void MultipleMessages()
        {
            var listenerA = new ListenerSpy();
            var listenerB = new ListenerSpy();

            receiver.SubscribeToMessage("AMessage", listenerA.Method);
            receiver.SubscribeToMessage("AnotherMessage", listenerB.Method);

            dispatcher.Broadcast("AMessage");

            Assert.IsTrue(listenerA.HasReceivedMessage);
            Assert.IsFalse(listenerB.HasReceivedMessage);
        }
        public void UnsubscribesMultipleListenersFromMessage()
        {
            var listenerA = new ListenerSpy();
            var listenerB = new ListenerSpy();

            receiver.SubscribeToMessage("AMessage", listenerA.Method);
            receiver.SubscribeToMessage("AMessage", listenerB.Method);
            receiver.UnsubscribeFromMessage("AMessage");

            dispatcher.Broadcast("AMessage");

            Assert.IsFalse(listenerA.HasReceivedMessage);
            Assert.IsFalse(listenerB.HasReceivedMessage);
        }