예제 #1
0
        public void RabbitMQSource_Publish_Success()
        {
            //----------------------Arrange----------------------
            var dependency  = new Depends(Depends.ContainerType.RabbitMQ);
            var queueSource = new ValidRealRabbitMQSourceForTestingAgainst(dependency);
            var queueName   = TestQueueNameGenerator.GetName;

            var config = new RabbitConfig
            {
                QueueName  = queueName,
                Exchange   = "",
                RoutingKey = queueName,
            };

            //----------------------Act--------------------------
            var message    = Guid.NewGuid().ToString();
            var data       = Encoding.UTF8.GetBytes(message);
            var connection = queueSource.NewConnection(config);

            try
            {
                var publisher = connection.NewPublisher(config);
                publisher.Publish(data);

                using (var testPublishSuccess = new TestPublishSuccess(dependency))
                {
                    var sentData = testPublishSuccess.GetSentMessage(config.QueueName);
                    //------------------------Assert----------------------
                    Assert.AreEqual(config.Exchange, sentData.Exchange);
                    Assert.AreEqual(config.RoutingKey, sentData.RoutingKey);
                    Assert.AreEqual(message, Encoding.UTF8.GetString(sentData.Body));
                }
            }
            finally
            {
                connection.DeleteQueue(config);
                connection.Dispose();
            }
        }
예제 #2
0
        public void RabbitMQSource_GivenSourceCreateNewConnection_Success()
        {
            //----------------------Arrange----------------------
            var queueSource = new ValidRealRabbitMQSourceForTestingAgainst(new Depends(Depends.ContainerType.RabbitMQ));
            var queueName   = TestQueueNameGenerator.GetName;

            var testConsumer = new TestConsumer();

            var config = new RabbitConfig
            {
                QueueName  = queueName,
                Exchange   = "",
                RoutingKey = queueName,
            };

            //----------------------Act--------------------------

            using (var connection = queueSource.NewConnection(config))
            {
                connection.StartConsuming(config, testConsumer);
            }

            int i = 0;

            while (!testConsumer.IsDataReceived)
            {
                Thread.Sleep(100);
                if (i >= 30)
                {
                    break;
                }
                i++;
            }
            //----------------------Assert-----------------------
            Assert.IsFalse(testConsumer.IsDataReceived);
        }