public void SendMessageDoesNothingOnEmptyDictionary()
        {
            // Arrange
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var dictionary = new Dictionary <TestBusKey, TestBusQueueWrapper <EventMessage> >();

            context.SetupGet(e => e.DataQueues)
            .Returns(dictionary);

            var sender = new TestMessageSender(context.Object);

            var message = new EventMessage {
                Topic = "UnknownTopic"
            };

            // Act
            sender.SendMessage(message);

            // Assert
            Assert.AreEqual(0, dictionary.Count);
        }
        public void SendMessageDoesNothingWithoutAvailableQueue(string topic)
        {
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var dictionary = new Dictionary <TestBusKey, TestBusQueueWrapper <EventMessage> >();

            context.SetupGet(e => e.DataQueues)
            .Returns(dictionary);

            var sender = new TestMessageSender(context.Object);

            var message = new EventMessage {
                Topic = "UnknownTopic"
            };

            // Act
            sender.SendMessage(message);

            // Assert
            var key = new TestBusKey("testQueue", topic);

            Assert.IsFalse(dictionary.ContainsKey(key));
        }
        public void TopicsAreSelectedByRegex(string regexTopic, string topic)
        {
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var dictionary = new Dictionary <TestBusKey, TestBusQueueWrapper <EventMessage> >();
            var key        = new TestBusKey("testQueue", topic);

            dictionary[key] = new TestBusQueueWrapper <EventMessage>();

            context.SetupGet(e => e.DataQueues)
            .Returns(dictionary);

            var sender  = new TestMessageSender(context.Object);
            var message = new EventMessage {
                Topic = topic
            };

            // Act
            sender.SendMessage(message);

            // Assert
            Assert.IsTrue(dictionary.ContainsKey(key));
        }
        public void SendMessageAddsMessageToQueueIfQueueExists(string topic)
        {
            Mock <TestBusContext> context = new Mock <TestBusContext>(MockBehavior.Strict);
            var dictionary = new Dictionary <TestBusKey, TestBusQueueWrapper <EventMessage> >();
            var key        = new TestBusKey("testQueue", topic);

            dictionary[key] = new TestBusQueueWrapper <EventMessage>();

            context.SetupGet(e => e.DataQueues)
            .Returns(dictionary);

            var sender = new TestMessageSender(context.Object);

            var message = new EventMessage {
                Topic = topic
            };

            // Act
            sender.SendMessage(message);

            // Assert
            Assert.IsTrue(dictionary.ContainsKey(key));
            Assert.AreEqual(1, dictionary[key].Queue.Count);
        }