public async Task Should_not_be_allowed_twice()
        {
            var loggerFactory = new TestOutputLoggerFactory(true);

            LogContext.ConfigureCurrentLogContext(loggerFactory);

            DiagnosticListener.AllListeners.Subscribe(new DiagnosticListenerObserver());

            var secondHarness = new RabbitMqTestHarness();

            try
            {
                Assert.That(async() =>
                {
                    using (var token = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
                    {
                        await secondHarness.Start(token.Token).OrCanceled(TestCancellationToken);

                        await secondHarness.Stop();
                    }
                }, Throws.TypeOf <RabbitMqConnectionException>());
            }
            finally
            {
                secondHarness.Dispose();
            }
        }
Exemplo n.º 2
0
        public async Task Should_properly_fail_on_exclusive_launch()
        {
            var harness1 = new RabbitMqTestHarness();

            harness1.OnConfigureRabbitMqBus += configurator =>
            {
                configurator.OverrideDefaultBusEndpointQueueName("exclusively-yours");
                configurator.Exclusive = true;
            };

            var harness2 = new RabbitMqTestHarness();

            harness2.OnConfigureRabbitMqBus += configurator =>
            {
                configurator.OverrideDefaultBusEndpointQueueName("exclusively-yours");
                configurator.Exclusive = true;
            };

            await harness1.Start();

            try
            {
                Assert.That(async() => await harness2.Start(), Throws.TypeOf <RabbitMqConnectionException>());

                await harness2.Stop();
            }
            finally
            {
                await Task.Delay(1000);

                await harness1.Stop();
            }
        }
Exemplo n.º 3
0
        public async Task Should_fan_out_published_messages()
        {
            var endpointSettings = new EndpointSettings <IEndpointDefinition <EventConsumer> > {
                InstanceId = "27"
            };
            var endpointDefinition = new ConsumerEndpointDefinition <EventConsumer>(endpointSettings);

            var firstHarness  = new RabbitMqTestHarness();
            var firstConsumer = new EventConsumer(firstHarness.GetTask <ConsumeContext <SomeEvent> >());

            firstHarness.OnConfigureRabbitMqBus += configurator =>
            {
                configurator.ReceiveEndpoint(endpointDefinition, KebabCaseEndpointNameFormatter.Instance, e =>
                {
                    e.Consumer(() => firstConsumer);
                });
            };

            await firstHarness.Start();

            try
            {
                endpointSettings = new EndpointSettings <IEndpointDefinition <EventConsumer> > {
                    InstanceId = "42"
                };
                endpointDefinition = new ConsumerEndpointDefinition <EventConsumer>(endpointSettings);

                var secondHarness  = new RabbitMqTestHarness();
                var secondConsumer = new EventConsumer(secondHarness.GetTask <ConsumeContext <SomeEvent> >());
                secondHarness.OnConfigureRabbitMqBus += configurator =>
                {
                    configurator.ReceiveEndpoint(endpointDefinition, KebabCaseEndpointNameFormatter.Instance, e =>
                    {
                        e.Consumer(() => secondConsumer);
                    });
                };

                await secondHarness.Start();

                try
                {
                    await firstHarness.Bus.Publish(new SomeEvent());

                    await firstConsumer.Completed;

                    await secondConsumer.Completed;
                }
                finally
                {
                    await secondHarness.Stop();
                }
            }
            finally
            {
                await firstHarness.Stop();
            }
        }
Exemplo n.º 4
0
        public async Task Should_not_be_allowed_twice()
        {
            var secondHarness = new RabbitMqTestHarness();

            try
            {
                Assert.That(async() =>
                {
                    await secondHarness.Start();

                    await secondHarness.Stop();
                }, Throws.TypeOf <RabbitMqConnectionException>());
            }
            finally
            {
                secondHarness.Dispose();
            }
        }
        public async Task Should_not_be_allowed_twice()
        {
            var secondHarness = new RabbitMqTestHarness();

            try
            {
                Assert.That(async() =>
                {
                    using (var token = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
                    {
                        await secondHarness.Start(token.Token);

                        await secondHarness.Stop();
                    }
                }, Throws.TypeOf <RabbitMqConnectionException>());
            }
            finally
            {
                secondHarness.Dispose();
            }
        }
        public async Task Should_not_be_allowed_twice()
        {
            var secondHarness = new RabbitMqTestHarness {
                CleanVirtualHost = false
            };

            try
            {
                Assert.That(async() =>
                {
                    using var token = new CancellationTokenSource(TimeSpan.FromSeconds(5));

                    await secondHarness.Start(token.Token).OrCanceled(TestCancellationToken);

                    await secondHarness.Stop();
                }, Throws.TypeOf <RabbitMqConnectionException>());
            }
            finally
            {
                secondHarness.Dispose();
            }
        }