public void MessageRouterTerminateWithConsumers()
        {
            MessageRouter target = new MessageRouter();
            PrivateObject obj    = new PrivateObject(target);
            LoggerUtility logger = new LoggerUtility("test");
            Mock <IMessageDestination> destMock = new Mock <IMessageDestination>();

            obj.SetFieldOrProperty("mLogger", logger);

            target.RegisterTopic("TESTTOPIC", destMock.Object);
            target.Terminate();

            Assert.IsTrue(logger.WarnMessages.Count > 0);
        }
        public void GetMessagesTest()
        {
            MessageRouter              target   = new MessageRouter();
            PrivateObject              obj      = new PrivateObject(target);
            Mock <IMessage>            msgMock  = new Mock <IMessage>();
            Mock <IMessage>            msgMock2 = new Mock <IMessage>();
            Mock <IMessage>            msgMock3 = new Mock <IMessage>();
            Mock <IMessage>            msgMock4 = new Mock <IMessage>();
            Mock <IMessageDestination> destMock = new Mock <IMessageDestination>();
            ConcurrentDictionary <string, List <IMessage> >            mCurrentFrameMessages   = (ConcurrentDictionary <string, List <IMessage> >)obj.GetFieldOrProperty("mCurrentFrameMessages");
            ConcurrentDictionary <IMessageDestination, List <string> > ConsumerTopicDictionary = (ConcurrentDictionary <IMessageDestination, List <string> >)obj.GetFieldOrProperty("ConsumerTopicDictionary");
            List <string> topics = new List <string>();

            topics.Add("TEST1");
            topics.Add("TEST3");
            topics.Add("TEST4");
            ConsumerTopicDictionary.TryAdd(destMock.Object, topics);
            List <IMessage> messages1 = new List <IMessage>();

            messages1.Add(msgMock.Object);
            messages1.Add(msgMock2.Object);
            List <IMessage> messages2 = new List <IMessage>();

            messages2.Add(msgMock3.Object);
            List <IMessage> messages3 = new List <IMessage>();

            messages3.Add(msgMock4.Object);
            mCurrentFrameMessages.TryAdd("TEST1", messages1);
            mCurrentFrameMessages.TryAdd("TEST2", messages2);
            mCurrentFrameMessages.TryAdd("TEST3", messages3);

            Dictionary <string, List <IMessage> > actual = target.GetMessages(destMock.Object);

            Assert.IsTrue(actual.ContainsKey("TEST1"));
            Assert.IsTrue(actual.ContainsKey("TEST3"));
            Assert.IsFalse(actual.ContainsKey("TEST4"));
            List <IMessage> actual1 = actual["TEST1"];

            Assert.IsTrue(actual1.Count == 2);
            Assert.IsTrue(actual1.Contains(msgMock.Object));
            Assert.IsTrue(actual1.Contains(msgMock2.Object));
            List <IMessage> actual2 = actual["TEST3"];

            Assert.IsTrue(actual2.Count == 1);
            Assert.IsTrue(actual2.Contains(msgMock4.Object));
        }
        public void DeregisterTopicLastConsumerTest()
        {
            MessageRouter target = new MessageRouter();
            PrivateObject obj    = new PrivateObject(target);
            ConcurrentDictionary <IMessageDestination, List <string> > ConsumerTopicDictionary = (ConcurrentDictionary <IMessageDestination, List <string> >)obj.GetFieldOrProperty("ConsumerTopicDictionary");
            ConcurrentDictionary <string, List <IMessageDestination> > TopicConsumerDictionary = (ConcurrentDictionary <string, List <IMessageDestination> >)obj.GetFieldOrProperty("TopicConsumerDictionary");
            Mock <IMessageDestination> destMock1 = new Mock <IMessageDestination>();
            Mock <IMessageDestination> destMock2 = new Mock <IMessageDestination>();
            Mock <IMessageDestination> destMock3 = new Mock <IMessageDestination>();

            target.RegisterTopic("TEST1", destMock1.Object);
            target.RegisterTopic("TEST3", destMock1.Object);
            target.RegisterTopic("TEST2", destMock2.Object);
            target.RegisterTopic("TEST1", destMock3.Object);

            target.DeregisterTopic("TEST2", destMock2.Object);

            Assert.IsFalse(ConsumerTopicDictionary.ContainsKey(destMock2.Object));
            Assert.IsFalse(TopicConsumerDictionary.ContainsKey("TEST2"));
        }
        public void RegisterTopicTest()
        {
            MessageRouter target = new MessageRouter();
            PrivateObject obj    = new PrivateObject(target);
            ConcurrentDictionary <IMessageDestination, List <string> > ConsumerTopicDictionary = (ConcurrentDictionary <IMessageDestination, List <string> >)obj.GetFieldOrProperty("ConsumerTopicDictionary");
            ConcurrentDictionary <string, List <IMessageDestination> > TopicConsumerDictionary = (ConcurrentDictionary <string, List <IMessageDestination> >)obj.GetFieldOrProperty("TopicConsumerDictionary");
            Mock <IMessageDestination> destMock1 = new Mock <IMessageDestination>();
            Mock <IMessageDestination> destMock2 = new Mock <IMessageDestination>();
            Mock <IMessageDestination> destMock3 = new Mock <IMessageDestination>();

            target.RegisterTopic("TEST1", destMock1.Object);
            target.RegisterTopic("TEST3", destMock1.Object);
            target.RegisterTopic("TEST2", destMock2.Object);
            target.RegisterTopic("TEST1", destMock3.Object);

            Assert.IsTrue(ConsumerTopicDictionary.ContainsKey(destMock1.Object));
            Assert.IsTrue(ConsumerTopicDictionary.ContainsKey(destMock2.Object));
            Assert.IsTrue(ConsumerTopicDictionary.ContainsKey(destMock3.Object));
            Assert.IsTrue(TopicConsumerDictionary.ContainsKey("TEST1"));
            Assert.IsTrue(TopicConsumerDictionary.ContainsKey("TEST2"));
            Assert.IsTrue(TopicConsumerDictionary.ContainsKey("TEST3"));
            List <string> dest1List = ConsumerTopicDictionary[destMock1.Object];

            Assert.IsTrue(dest1List.Count == 2);
            Assert.IsTrue(dest1List.Contains("TEST1"));
            Assert.IsTrue(dest1List.Contains("TEST3"));
            List <IMessageDestination> topic1List = TopicConsumerDictionary["TEST1"];

            Assert.IsTrue(topic1List.Count == 2);
            Assert.IsTrue(topic1List.Contains(destMock1.Object));
            Assert.IsTrue(topic1List.Contains(destMock3.Object));
            List <string> dest2List = ConsumerTopicDictionary[destMock2.Object];

            Assert.IsTrue(dest2List.Count == 1);
            Assert.IsTrue(dest2List.Contains("TEST2"));
            List <IMessageDestination> topic2List = TopicConsumerDictionary["TEST2"];

            Assert.IsTrue(topic2List.Count == 1);
            Assert.IsTrue(topic2List.Contains(destMock2.Object));
        }
        public void SendMessageTest()
        {
            MessageRouter   target   = new MessageRouter();
            PrivateObject   obj      = new PrivateObject(target);
            Mock <IMessage> msgMock  = new Mock <IMessage>();
            Mock <IMessage> msgMock2 = new Mock <IMessage>();
            Mock <IMessage> msgMock3 = new Mock <IMessage>();
            ConcurrentDictionary <string, List <IMessage> > mNextFrameMessages = (ConcurrentDictionary <string, List <IMessage> >)obj.GetFieldOrProperty("mNextFrameMessages");

            target.SendMessage("TEST1", msgMock.Object);
            target.SendMessage("TEST2", msgMock2.Object);
            target.SendMessage("TEST1", msgMock3.Object);

            Assert.IsTrue(mNextFrameMessages.ContainsKey("TEST1"));
            Assert.IsTrue(mNextFrameMessages.ContainsKey("TEST2"));
            List <IMessage> actual = mNextFrameMessages["TEST1"];

            Assert.AreEqual(actual.Count, 2);
            Assert.IsTrue(actual.Contains(msgMock.Object));
            Assert.IsTrue(actual.Contains(msgMock3.Object));
            actual = mNextFrameMessages["TEST2"];
            Assert.AreEqual(actual.Count, 1);
            Assert.IsTrue(actual.Contains(msgMock2.Object));
        }