Exemple #1
0
        public void QueuePurge_RemovesAllMessagesFromQueue()
        {
            // Arrange
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                model.QueueDeclarePassive("my_other_queue");
                node.Queues["my_other_queue"].Messages.Enqueue(new RabbitMessage());
                node.Queues["my_other_queue"].Messages.Enqueue(new RabbitMessage());

                model.QueueDeclarePassive("my_queue");
                node.Queues["my_queue"].Messages.Enqueue(new RabbitMessage());
                node.Queues["my_queue"].Messages.Enqueue(new RabbitMessage());
                node.Queues["my_queue"].Messages.Enqueue(new RabbitMessage());
                node.Queues["my_queue"].Messages.Enqueue(new RabbitMessage());

                // Act
                model.QueuePurge("my_queue");

                // Assert
                Assert.True(node.Queues["my_queue"].Messages.IsEmpty);
                Assert.False(node.Queues["my_other_queue"].Messages.IsEmpty);
            }
        }
Exemple #2
0
        public void QueueDeclarePassive_throws_if_queue_does_not_exist()
        {
            var server = new RabbitServer();

            using (var model = new FakeModel(server))
            {
                const string queueName = "myQueue";
                Assert.Throws <OperationInterruptedException>(() => model.QueueDeclarePassive(queueName));
            }
        }
Exemple #3
0
        public void QueueDeclarePassive_does_not_throw_if_queue_exists()
        {
            var server = new RabbitServer();

            using (var model = new FakeModel(server))
            {
                const string queueName = "myQueue";
                model.QueueDeclare(queueName);
                model.QueueDeclarePassive(queueName);
            }

            Assert.True(true); // The test is successful if it does not throw
        }
Exemple #4
0
        public void BasicGet_NoMessageOnQueue_ReturnsNull()
        {
            // Arrange
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                model.QueueDeclarePassive("my_queue");

                // Act
                var response = model.BasicGet("my_queue", false);

                // Assert
                Assert.Null(response);
            }
        }
Exemple #5
0
        public void QueueDeclarePassive_WithName_CreatesQueue()
        {
            // Arrange
            var node  = new RabbitServer();
            var model = new FakeModel(node);

            const string queueName = "myQueue";

            // Act
            model.QueueDeclarePassive(queueName);

            // Assert
            Assert.Single(node.Queues);
            Assert.Equal(queueName, node.Queues.First().Key);
            Assert.Equal(queueName, node.Queues.First().Value.Name);
        }
Exemple #6
0
        public void BasicPublish_PublishesMessage()
        {
            // Arrange
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                model.ExchangeDeclare("my_exchange", ExchangeType.Direct);
                model.QueueDeclarePassive("my_queue");
                model.ExchangeBind("my_queue", "my_exchange", null);

                var message        = "hello world!";
                var encodedMessage = Encoding.ASCII.GetBytes(message);

                // Act
                model.BasicPublish("my_exchange", null, new BasicProperties(), encodedMessage);

                // Assert
                Assert.Single(node.Queues["my_queue"].Messages);
                Assert.Equal(encodedMessage, node.Queues["my_queue"].Messages.First().Body);
            }
        }
Exemple #7
0
        public void QueueBind_BindsAnExchangeToAQueue()
        {
            // Arrange
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                const string queueName    = "someQueue";
                const string exchangeName = "someExchange";
                const string routingKey   = "someRoutingKey";
                var          arguments    = new Dictionary <string, object>();

                model.ExchangeDeclare(exchangeName, "direct");
                model.QueueDeclarePassive(queueName);

                // Act
                model.QueueBind(queueName, exchangeName, routingKey, arguments);

                // Assert
                AssertBinding(node, exchangeName, routingKey, queueName);
            }
        }
Exemple #8
0
        public void BasicGet_MessageOnQueue_GetsMessage()
        {
            // Arrange
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                model.ExchangeDeclare("my_exchange", ExchangeType.Direct);
                model.QueueDeclarePassive("my_queue");
                model.ExchangeBind("my_queue", "my_exchange", null);

                var message        = "hello world!";
                var encodedMessage = Encoding.ASCII.GetBytes(message);
                model.BasicPublish("my_exchange", null, new BasicProperties(), encodedMessage);

                // Act
                var response = model.BasicGet("my_queue", false);

                // Assert
                Assert.Equal(encodedMessage, response.Body);
                Assert.True(response.DeliveryTag > 0ul);
            }
        }
Exemple #9
0
        public void BasicAck()
        {
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                model.ExchangeDeclare("my_exchange", ExchangeType.Direct);
                model.QueueDeclarePassive("my_queue");
                model.ExchangeBind("my_queue", "my_exchange", null);

                var message        = "hello world!";
                var encodedMessage = Encoding.ASCII.GetBytes(message);
                model.BasicPublish("my_exchange", null, new BasicProperties(), encodedMessage);
                model.BasicConsume("my_queue", false, new EventingBasicConsumer(model));

                // Act
                var deliveryTag = model.WorkingMessages.First().Key;
                model.BasicAck(deliveryTag, false);

                // Assert
                Assert.Empty(node.Queues["my_queue"].Messages);
            }
        }
Exemple #10
0
        public void QueueUnbind_RemovesBinding()
        {
            // Arrange
            var node = new RabbitServer();

            using (var model = new FakeModel(node))
            {
                const string queueName    = "someQueue";
                const string exchangeName = "someExchange";
                const string routingKey   = "someRoutingKey";
                var          arguments    = new Dictionary <string, object>();

                model.ExchangeDeclare(exchangeName, "direct");
                model.QueueDeclarePassive(queueName);
                model.ExchangeBind(exchangeName, queueName, routingKey, arguments);

                // Act
                model.QueueUnbind(queueName, exchangeName, routingKey, arguments);

                // Assert
                Assert.True(node.Exchanges[exchangeName].Bindings.IsEmpty);
                Assert.True(node.Queues[queueName].Bindings.IsEmpty);
            }
        }