public void DeregisterTopicTest() { 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("TEST1", destMock1.Object); List <string> dest1List = ConsumerTopicDictionary[destMock1.Object]; Assert.IsTrue(dest1List.Count == 1); Assert.IsTrue(dest1List.Contains("TEST3")); List <IMessageDestination> topic1List = TopicConsumerDictionary["TEST1"]; Assert.IsTrue(topic1List.Count == 1); 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 SendMessageImmediateTest() { MessageRouter target = new MessageRouter(); PrivateObject obj = new PrivateObject(target); object ret = new object(); Mock <IMessage> msgMock = new Mock <IMessage>(); 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>(); destMock1.Setup(f => f.HandleMessage("TEST1", msgMock.Object, ref ret)).Returns(true); Mock <IMessageDestination> destMock3 = new Mock <IMessageDestination>(); destMock3.Setup(f => f.HandleMessage("TEST1", msgMock.Object, ref ret)).Returns(false); target.RegisterTopic("TEST1", destMock1.Object); target.RegisterTopic("TEST1", destMock3.Object); bool actual = target.SendMessageImmediate("TEST1", msgMock.Object, ref ret); Assert.IsTrue(actual); destMock1.Verify(f => f.HandleMessage("TEST1", msgMock.Object, ref ret), Times.Once()); actual = target.SendMessageImmediate("TEST1", msgMock.Object, ref ret); Assert.IsFalse(actual); destMock3.Verify(f => f.HandleMessage("TEST1", msgMock.Object, ref ret), Times.Once()); actual = target.SendMessageImmediate("TEST1", msgMock.Object, ref ret); Assert.IsTrue(actual); destMock1.Verify(f => f.HandleMessage("TEST1", msgMock.Object, ref ret), Times.Exactly(2)); }
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 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); }