Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
 public override void Dispose()
 {
     TestChannel.ExchangeDelete("rawrabbit.integrationtests.testmessages");
     TestChannel.QueueDelete("basicmessage");
     TestChannel.QueueDelete("simplemessage");
     base.Dispose();
 }
Esempio n. 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);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        public async Task Should_Be_Able_To_Subscribe_Initialized_Queue_And_Exchange()
        {
            using (var client = TestClientFactory.CreateNormal())
            {
                /* Setup */
                const string exchangeName = "initialized.exchange";
                const string queueName    = "initialized.queue";

                try
                {
                    TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Fanout);
                    TestChannel.QueueDeclare(queueName, true, false, false);

                    var tcs = new TaskCompletionSource <DynamicMessage>();
                    client.SubscribeAsync <DynamicMessage>((message, context) =>
                    {
                        tcs.TrySetResult(message);
                        return(Task.FromResult(true));
                    }, cfg => cfg
                                                           .WithQueue(q => q
                                                                      .AssumeInitialized()
                                                                      .WithName(queueName))
                                                           .WithSubscriberId(string.Empty)
                                                           .WithExchange(e => e
                                                                         .AssumeInitialized()
                                                                         .WithName(exchangeName)));

                    /* Test */
                    await client.PublishAsync(new DynamicMessage { Body = new { IsDynamic = true } },
                                              configuration : cfg => cfg
                                              .WithExchange(e => e
                                                            .AssumeInitialized()
                                                            .WithName(exchangeName)));

                    await tcs.Task;

                    /* Assert */
                    Assert.True(tcs.Task.Result.Body.IsDynamic);
                }
                finally
                {
                    /* Teardown */
                    TestChannel.QueueDelete(queueName);
                    TestChannel.ExchangeDelete(exchangeName);
                }
            }
        }
Esempio n. 7
0
        public async Task Should_Honor_Last_Configuration()
        {
            /* Setup */
            var          client       = RawRabbitFactory.GetExtendableClient();
            const string exchangeName = "topology";

            TestChannel.ExchangeDelete(exchangeName);

            /* Test */
            var result = await client.UpdateTopologyAsync(c => c
                                                          .ForExchange(exchangeName)
                                                          .UseConfiguration(e => e.WithType(ExchangeType.Headers))
                                                          .ForExchange(exchangeName)
                                                          .UseConfiguration(e => e.WithType(ExchangeType.Topic))
                                                          .ForExchange(exchangeName)
                                                          .UseConfiguration(e => e.WithType(ExchangeType.Direct))
                                                          .ForExchange(exchangeName)
                                                          .UseConfiguration(e => e.WithType(ExchangeType.Fanout)));

            /* Assert */
            Assert.Equal(result.Exchanges[0].Exchange.ExchangeType, ExchangeType.Fanout.ToString().ToLower());
        }
Esempio n. 8
0
        public async Task Should_Update_Exhange_Type()
        {
            /* Setup */
            const string exchangeName = "topology";

            TestChannel.ExchangeDelete(exchangeName);
            TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Direct);

            var client = RawRabbitFactory.GetExtendableClient() as ExtendableBusClient <MessageContext>;

            /* Test */
            await client.UpdateTopologyAsync(t => t
                                             .ForExchange(exchangeName)
                                             .UseConfiguration(e => e
                                                               .WithType(ExchangeType.Topic)
                                                               .WithDurability(false))
                                             );

            /* Assert */
            TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Topic);
            Assert.True(true, "Did not throw");
            Assert.Throws <OperationInterruptedException>(() => TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Direct));
        }
Esempio n. 9
0
 public override void Dispose()
 {
     try { TestChannel.ExchangeDelete("rawrabbit.integrationtests.testmessages"); }
     catch (Exception) { }
     base.Dispose();
 }
Esempio n. 10
0
 public TopologyUpdaterTests()
 {
     TestChannel.ExchangeDelete("rawrabbit.integrationtests.testmessages");
 }
Esempio n. 11
0
 public TopicExchangeTests()
 {
     TestChannel.ExchangeDelete("rawrabbit.integrationtests.testmessages");
     TestChannel.QueueDelete("basicmessage");
     TestChannel.QueueDelete("simplemessage");
 }