public async Task Should_Be_Able_To_Get_Message_When_Batch_Size_Is_Smaller_Than_Queue_Length()
        {
            using (var client = ZyRabbitFactory.CreateTestClient())
            {
                /* Setup */
                var message = new BasicMessage {
                    Prop = "Get me, get it?"
                };
                var conventions  = new NamingConventions();
                var exchangeName = conventions.ExchangeNamingConvention(message.GetType());
                TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null);
                TestChannel.ExchangeDeclare(conventions.ExchangeNamingConvention(message.GetType()), ExchangeType.Topic);
                TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), conventions.ExchangeNamingConvention(message.GetType()), conventions.RoutingKeyConvention(message.GetType()) + ".#");

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                /* Test */
                var ackable = await client.GetManyAsync <BasicMessage>(2);

                TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType()));
                TestChannel.ExchangeDelete(exchangeName);

                /* Assert */
                Assert.NotNull(ackable);
                Assert.Equal(ackable.Content.Count, 2);
            }
        }
        public async Task Should_Be_Able_To_Ack_Messages_And_Then_Full_List()
        {
            using (var client = ZyRabbitFactory.CreateTestClient())
            {
                /* Setup */
                var message = new BasicMessage {
                    Prop = "Get me, get it?"
                };
                var conventions  = new NamingConventions();
                var exchangeName = conventions.ExchangeNamingConvention(message.GetType());
                TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null);
                TestChannel.ExchangeDeclare(conventions.ExchangeNamingConvention(message.GetType()), ExchangeType.Topic);
                TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), exchangeName, conventions.RoutingKeyConvention(message.GetType()) + ".#");

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                /* Test */
                var ackable = await client.GetManyAsync <BasicMessage>(3);

                ackable.Content[1].Ack();
                ackable.Ack();
                TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType()));
                TestChannel.ExchangeDelete(exchangeName);

                /* Assert */
                Assert.True(true);
            }
        }
        public async Task Should_Be_Able_To_Subscibe_To_Pure_Json_Message()
        {
            var conventions = new NamingConventions();

            using (var client = TestClientFactory.CreateNormal(ioc => ioc.AddSingleton <INamingConventions>(c => conventions)))
            {
                /* Setup */
                var tcs          = new TaskCompletionSource <BasicMessage>();
                var subscription = client.SubscribeAsync <BasicMessage>((message, context) =>
                {
                    tcs.TrySetResult(message);
                    return(Task.FromResult(true));
                });
                var uniqueValue = Guid.NewGuid().ToString();
                var jsonMsg     = JsonConvert.SerializeObject(new BasicMessage {
                    Prop = uniqueValue
                });

                /* Test */
                TestChannel.BasicPublish(
                    conventions.ExchangeNamingConvention(typeof(BasicMessage)),
                    conventions.QueueNamingConvention(typeof(BasicMessage)),
                    true,
                    null,
                    Encoding.UTF8.GetBytes(jsonMsg));
                await tcs.Task;

                /* Assert */
                Assert.Equal(uniqueValue, tcs.Task.Result.Prop);
            }
        }
Exemple #4
0
        public async Task Should_Be_Able_To_Get_BasicGetResult_Message()
        {
            using (var client = ZyRabbitFactory.CreateTestClient())
            {
                /* Setup */
                var message = new BasicMessage {
                    Prop = "Get me, get it?"
                };
                var conventions  = new NamingConventions();
                var exchangeName = conventions.ExchangeNamingConvention(message.GetType());
                var queueName    = conventions.QueueNamingConvention(message.GetType());
                TestChannel.QueueDeclare(queueName, true, false, false, null);
                TestChannel.ExchangeDeclare(exchangeName, ExchangeType.Topic);
                TestChannel.QueueBind(queueName, exchangeName, conventions.RoutingKeyConvention(message.GetType()) + ".#");

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                /* Test */
                var ackable = await client.GetAsync(cfg => cfg.FromQueue(queueName));

                /* Assert */
                Assert.NotNull(ackable);
                Assert.NotEmpty(ackable.Content.Body);
                TestChannel.QueueDelete(queueName);
                TestChannel.ExchangeDelete(exchangeName);
            }
        }
        public async Task Should_Be_Able_To_Nack_One_In_Batch()
        {
            using (var client = ZyRabbitFactory.CreateTestClient())
            {
                /* Setup */
                var message = new BasicMessage {
                    Prop = "Get me, get it?"
                };
                var nacked = new BasicMessage {
                    Prop = "Not me! Plz?"
                };
                var conventions  = new NamingConventions();
                var exchangeName = conventions.ExchangeNamingConvention(message.GetType());
                TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null);
                TestChannel.ExchangeDeclare(exchangeName, ExchangeType.Topic);
                TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), conventions.ExchangeNamingConvention(message.GetType()), conventions.RoutingKeyConvention(message.GetType()) + ".#");

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                await client.PublishAsync(nacked, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName)));

                /* Test */
                var ackableList = await client.GetManyAsync <BasicMessage>(3);

                foreach (var ackableMsg in ackableList.Content)
                {
                    if (string.Equals(ackableMsg.Content.Prop, message.Prop))
                    {
                        ackableMsg.Ack();
                    }
                    else
                    {
                        ackableMsg.Nack();
                    }
                }
                var getAgain = await client.GetAsync <BasicMessage>();

                TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType()));
                TestChannel.ExchangeDelete(exchangeName);

                /* Assert */
                Assert.NotNull(getAgain);
                Assert.Equal(getAgain.Content.Prop, nacked.Prop);
            }
        }