Пример #1
0
        public void BasicCancel_works_for_asynchronous_consumers()
        {
            var server = new RabbitServer();

            using (var model = new FakeModel(server))
            {
                model.QueueDeclare("my_queue");
                var expectedConsumerTag = "foo";

                var consumer = new FakeAsyncDefaultBasicConsumer(model);

                model.BasicConsume("my_queue", false, expectedConsumerTag, consumer);
                Assert.True(consumer.IsRunning);
                model.BasicCancel(expectedConsumerTag);
                Assert.False(consumer.IsRunning);

                Assert.Equal(expectedConsumerTag, consumer.LastCancelOkConsumerTag);
            }
        }
Пример #2
0
        public void BasicConsume_works_for_asynchronous_consumers()
        {
            var server = new RabbitServer();

            using (var model = new FakeModel(server))
            {
                model.ExchangeDeclare("my_exchange", ExchangeType.Direct);
                model.QueueDeclare("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);

                var consumer = new FakeAsyncDefaultBasicConsumer(model);
                model.BasicConsume("my_queue", false, consumer);
                Assert.True(consumer.IsRunning);

                Assert.Equal(encodedMessage, consumer.LastDelivery.body);
            }
        }