public void SendCommandAddsValueToDestinationQueue(string queueName, string message)
        {
            // Arrange
            var context    = new Mock <TestBusContext>();
            var dictionary = new Dictionary <string, TestBusQueueWrapper <CommandMessage> >();

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

            dictionary[queueName] = new TestBusQueueWrapper <CommandMessage>();

            var sender  = new TestCommandSender(context.Object);
            var request = new CommandMessage
            {
                DestinationQueue = queueName,
                ReplyQueue       = "reply.queue",
                CorrelationId    = Guid.Empty,
                Body             = Encoding.Unicode.GetBytes(message)
            };

            // Act
            sender.SendCommandAsync(request);

            Thread.Sleep(WaitTime);

            // Assert
            Assert.IsTrue(dictionary.ContainsKey(queueName));
            dictionary[queueName].Queue.TryDequeue(out var result);
            Assert.AreEqual(message, Encoding.Unicode.GetString(result.Body));
        }
        public void QueueIsInitialized()
        {
            // Act
            TestBusQueueWrapper <EventMessage> queue = new TestBusQueueWrapper <EventMessage>();

            // Assert
            Assert.IsNotNull(queue.Queue);
        }
        public void ResetEventInitialStateIsFalse()
        {
            // Act
            TestBusQueueWrapper <EventMessage> queue = new TestBusQueueWrapper <EventMessage>();

            // Assert
            Assert.IsFalse(queue.AutoResetEvent.WaitOne(0));
        }
        public void ResetEventIsInitialized()
        {
            // Act
            TestBusQueueWrapper <EventMessage> queue = new TestBusQueueWrapper <EventMessage>();

            // Assert
            Assert.IsNotNull(queue.AutoResetEvent);
        }
        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);
        }