public When_a_ConnectionCreatedEvent_is_published()
        {
            persistentConnection = Substitute.For <IPersistentConnection>();
            var configuration = new ConnectionConfiguration();

            eventBus = new EventBus();
            var persistentChannel = new PersistentChannel(persistentConnection, configuration, eventBus);
        }
Esempio n. 2
0
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub <IPersistentConnection>();
            persistentConnection.Stub(x => x.CreateModel());
            var configuration = new ConnectionConfiguration();

            eventBus = new EventBus();
            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();

            var persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);
        }
        public When_an_action_is_invoked()
        {
            persistentConnection = Substitute.For <IPersistentConnection>();
            channel = Substitute.For <IModel, IRecoverable>();

            persistentConnection.CreateModel().Returns(channel);

            persistentChannel = new PersistentChannel(
                new PersistentChannelOptions(), persistentConnection, Substitute.For <IEventBus>()
                );

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Esempio n. 4
0
        public When_an_action_is_performed_on_a_closed_channel_that_doesnt_open_again()
        {
            var persistentConnection = Substitute.For <IPersistentConnection>();
            var eventBus             = Substitute.For <IEventBus>();
            var shutdownArgs         = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpErrorCodes.ConnectionClosed,
                "connection closed by peer"
                );
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.When(x => x.CreateModel()).Do(x => throw exception);
            persistentChannel = new PersistentChannel(new PersistentChannelOptions(), persistentConnection, eventBus);
        }
        public void Should_throw_exception_and_close_channel(Exception exception)
        {
            var persistentConnection = Substitute.For <IPersistentConnection>();
            var brokenChannel        = Substitute.For <IModel, IRecoverable>();

            brokenChannel.When(x => x.ExchangeDeclare("MyExchange", "direct"))
            .Do(x => throw exception);

            persistentConnection.CreateModel().Returns(x => brokenChannel);

            using var persistentChannel = new PersistentChannel(
                      new PersistentChannelOptions(), persistentConnection, Substitute.For <IEventBus>()
                      );

            Assert.Throws(
                exception.GetType(),
                () => persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"))
                );

            brokenChannel.Received().ExchangeDeclare("MyExchange", "direct");
            brokenChannel.Received().Close();
            brokenChannel.Received().Dispose();
        }
        public void Should_succeed_after_channel_recreation(Exception exception)
        {
            var persistentConnection = Substitute.For <IPersistentConnection>();
            var brokenChannel        = Substitute.For <IModel, IRecoverable>();

            brokenChannel.When(x => x.ExchangeDeclare("MyExchange", "direct"))
            .Do(x => throw exception);
            var channel = Substitute.For <IModel, IRecoverable>();

            persistentConnection.CreateModel().Returns(x => brokenChannel, x => channel);

            using var persistentChannel = new PersistentChannel(
                      new PersistentChannelOptions(), persistentConnection, Substitute.For <IEventBus>()
                      );

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));

            brokenChannel.Received().ExchangeDeclare("MyExchange", "direct");
            brokenChannel.Received().Close();
            brokenChannel.Received().Dispose();

            channel.Received().ExchangeDeclare("MyExchange", "direct");
        }
Esempio n. 7
0
        public When_an_action_is_performed_on_a_closed_channel_that_then_opens()
        {
            var persistentConnection = Substitute.For <IPersistentConnection>();

            channel = Substitute.For <IModel, IRecoverable>();
            var eventBus = new EventBus();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpErrorCodes.ConnectionClosed,
                "connection closed by peer"
                );
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.CreateModel().Returns(
                x => throw exception, x => channel, x => channel
                );

            var persistentChannel = new PersistentChannel(
                new PersistentChannelOptions(), persistentConnection, eventBus
                );

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }