Exemplo n.º 1
0
 public void CreateBus()
 {
     m_Sender      = Substitute.For <IMessageSender>();
     m_Receiver    = Substitute.For <IMessageReceiver>();
     m_MessageList = Substitute.For <IMessageRegistrationList>();
     m_MessageList.Messages.Returns(new List <Type>
     {
         typeof(TestMessage)
     });
     m_Bus = new MessageBus(m_Sender,
                            m_Receiver,
                            m_MessageList);
 }
 public void CreateBus()
 {
     m_Sender = Substitute.For<IMessageSender>();
     m_Receiver = Substitute.For<IMessageReceiver>();
     m_MessageList = Substitute.For<IMessageRegistrationList>();
     m_MessageList.Messages.Returns(new List<Type>
     {
         typeof(TestMessage)
     });
     m_Bus = new MessageBus(m_Sender,
                            m_Receiver,
                            m_MessageList);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new bus that will use the sender and reciever provided communication outside of the buses context
        /// </summary>
        /// <param name="messageSender">Shared isntance of the sender</param>
        /// <param name="messageReceiver">Shared instance of the receiver</param>
        /// /// <param name="messageList">The collection of message types to register for serialisation</param>
        public MessageBus(IMessageSender messageSender,
                          IMessageReceiver messageReceiver,
                          IMessageRegistrationList messageList)
        {
            m_Lock        = new object();
            m_Subscribers = new Dictionary <Type, Delegate>();

            m_MessageList     = messageList;
            m_MessageSender   = messageSender;
            m_MessageReceiver = messageReceiver;

            m_MessageSerialiser = new MessageSerialiser();
            foreach (var messageType in m_MessageList.Messages)
            {
                m_MessageSerialiser.Register(messageType);
            }

            m_Disposer = new Disposer();

            m_MessageReceiver.AddListener(ReceiveFromRemote).AddTo(m_Disposer);

            m_Messages = new ConcurrentQueue <IMessage>();
        }