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

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

                var messages        = new[] { "hello world!", "Thank you, @inbarbarkai" };
                var encodedMessages = messages.Select(m => Encoding.ASCII.GetBytes(m)).ToArray();

                var batch = model.CreateBasicPublishBatch();
                batch.Add("my_exchange", null, true, new BasicProperties(), encodedMessages[0]);
                batch.Add("my_exchange", null, true, new BasicProperties(), encodedMessages[1]);
                batch.Publish();

                Assert.Equal(2, node.Queues["my_queue"].Messages.Count);

                var index = 0;
                foreach (var item in node.Queues["my_queue"].Messages)
                {
                    Assert.Equal(encodedMessages[index], item.Body);
                    index++;
                }
            }
        }