public void Should_not_create_exchange_and_write_warning_log_if_exchangeName_is_null_or_empty()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.DeclareExchange(new ExchangeSetupData(), model, null);

            // Assert
            model.DidNotReceive().ExchangeDeclare(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>(), Arg.Any <IDictionary>());
            setup.Watcher.Received(1).WarnFormat(Arg.Any <string>(), Arg.Any <object[]>());
        }
示例#2
0
        public void Should_destroy_exchange_queues()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.Destroy <Customer>(new ExchangeSetupData(), new QueueSetupData());

            // Assert
            model.Received().QueueDelete("Queue.Customer");
            model.Received().ExchangeDelete("Exchange.Customer");
        }
示例#3
0
        public void Should_not_bind_and_write_warning_log_if_exchangeName_is_null_or_empty()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.BindQueue <Customer>(model, new QueueSetupData(), null, "", "");

            // Assert
            model.DidNotReceive().QueueBind(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
            setup.Watcher.Received(1).WarnFormat(Arg.Any <string>(), Arg.Any <object[]>());
        }
        public void Should_catch_OperationInterruptedException_and_log_error_when_trying_to_create_a_queue()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.QueueDeclare("Queue.Customer", true, false, false, Arg.Any <IDictionary>())).Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "Other error"));
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.SetupExchangeAndQueueFor <Customer>(new ExchangeSetupData(), new QueueSetupData());
        }
        public void Should_catch_OperationInterruptedException_when_trying_to_create_an_exist_exchange_but_configuration_not_match()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.ExchangeDeclare("Exchange.Customer", Arg.Any <string>(), true, false, null)).Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "PRECONDITION_FAILED - "));
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.SetupExchangeAndQueueFor <Customer>(new ExchangeSetupData(), new QueueSetupData());
        }
示例#6
0
        public void Should_not_throw_error_if_cannot_delete_exchange()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.ExchangeDelete("Exchange.Customer")).Do(callInfo =>
            {
                throw new Exception("Test Exception");
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.Destroy <Customer>(new ExchangeSetupData(), new QueueSetupData());
        }
示例#7
0
        public void Should_catch_OperationInterruptedException_when_trying_to_delete_none_exist_exchange()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.ExchangeDelete("Exchange.Customer")).Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "NOT_FOUND - no exchange "));
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.Destroy <Customer>(new ExchangeSetupData(), new QueueSetupData());
        }
        public void Should_catch_OperationInterruptedException_and_log_error_when_trying_to_create_an_exchange()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.ExchangeDeclare("Exchange.Customer", Arg.Any <string>(), true, false, null)).Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "Other error"));
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.CreateRoute <Customer>(_routeSetupData);
        }
        public void Should_catch_OperationInterruptedException_when_trying_to_create_an_exist_queue_but_configuration_not_match()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.QueueDeclare("Queue.Customer", true, false, false, Arg.Any <IDictionary>())).Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "PRECONDITION_FAILED - "));
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.CreateRoute <Customer>(_routeSetupData);
        }
        public void Should_create_exchange_queues_and_bind_them()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.CreateRoute <Customer>(_routeSetupData);

            // Assert
            model.Received().ExchangeDeclare("Exchange.Customer", "direct", true, false, _routeSetupData.ExchangeSetupData.Arguments);
            model.Received().QueueDeclare("Queue.Customer", true, false, false, _routeSetupData.QueueSetupData.Arguments);
            model.Received().QueueBind("Queue.Customer", "Exchange.Customer", "Customer", _routeSetupData.OptionalBindingData);
        }
        public void Should_not_throw_exception_if_cannot_bind_queues()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.QueueBind("Queue.Customer", "Exchange.Customer", "Customer")).Do(callInfo =>
            {
                throw new Exception("Test Exception");
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.CreateRoute <Customer>(_routeSetupData);
        }
示例#12
0
        public void Should_catch_OperationInterruptedException_and_log_error_when_trying_to_delete_queue()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.QueueDelete("Queue.Customer")).Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 1, "Other error"));
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.DestroyRoute <Customer>(_routeSetupData);
        }
        public void Should_apply_DeadLetter_params()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            _routeSetupData.QueueSetupData.DeadLetterExchange   = "DeadLetterExchange.Name";
            _routeSetupData.QueueSetupData.DeadLetterRoutingKey = "DeadLetterRoutingKey.Name";

            // Action
            setup.CreateRoute <Customer>(_routeSetupData);

            // Assert
            model.Received(1).QueueDeclare(Arg.Any <string>(), true, false, false, Arg.Is <IDictionary>(dic => dic.Count == 4));
        }
示例#14
0
        public void Should_catch_all_exception()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            model.When(x => x.QueueBind(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <IDictionary <string, object> >()))
            .Do(info => { throw new Exception(); });

            // Action
            setup.BindQueue <Customer>(model, new QueueSetupData(), "Exchange", "Queue", "Key");

            // Assert
            setup.Watcher.Received(1).Error(Arg.Any <Exception>());
        }
示例#15
0
        public void Should_bind_with_provided_params()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            var queueSetupData = new QueueSetupData();

            queueSetupData.Arguments.Add("Key1", "Val1");
            setup.BindQueue <Customer>(model, queueSetupData, "ExchangeName", "QueueName", "RoutingKey");

            // Assert
            model.Received().QueueBind(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Is <IDictionary <string, object> >(arg => arg["Key1"] == "Val1"));
        }
        public void Should_not_throw_exception_if_cannot_declare_queue()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.QueueDeclare("Queue.Customer", true, false, false, Arg.Any <IDictionary>())).Do(callInfo =>
            {
                throw new Exception("Test Exception");
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.CreateRoute <Customer>(_routeSetupData);

            // Assert
            model.Received().QueueBind("Queue.Customer", "Exchange.Customer", "Customer", _routeSetupData.OptionalBindingData);
        }
示例#17
0
        public void Should_not_throw_error_if_cannot_delete_queue()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.QueueDelete("Queue.Customer")).Do(callInfo =>
            {
                throw new Exception("Test Exception");
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.DestroyRoute <Customer>(_routeSetupData);

            // Assert
            model.Received().ExchangeDelete("Exchange.Customer");
        }
        public void Should_not_throw_exception_if_cannot_declare_exchange()
        {
            // Arrange
            var model = Substitute.For <IModel>();

            model.When(x => x.ExchangeDeclare("Exchange.Customer", "direct", true, false, null)).Do(callInfo =>
            {
                throw new Exception("Test Exception");
            });
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.SetupExchangeAndQueueFor <Customer>(new ExchangeSetupData(), new QueueSetupData());

            // Assert
            model.Received().QueueDeclare("Queue.Customer", true, false, false, Arg.Any <IDictionary>());
            model.Received().QueueBind("Queue.Customer", "Exchange.Customer", "Customer");
        }
        public void Should_create_exchange_queues_and_bind_them()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            // Action
            setup.SetupExchangeAndQueueFor <Customer>(new ExchangeSetupData(), new QueueSetupData
            {
                AutoExpire        = 10000,
                MessageTimeToLive = 10000000
            });

            // Assert
            model.Received().ExchangeDeclare("Exchange.Customer", "direct", true, false, null);
            model.Received().QueueDeclare("Queue.Customer", true, false, false, Arg.Any <IDictionary>());
            model.Received().QueueBind("Queue.Customer", "Exchange.Customer", "Customer");
        }
        public void Should_catch_OperationInterruptedException_and_write_errorLog()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            model.When(x => x.ExchangeDeclare(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>(), Arg.Any <IDictionary <string, object> >()))
            .Do(callInfo =>
            {
                throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Library, 101, "Some errors"));
            });

            // Action
            setup.DeclareExchange(new ExchangeSetupData(), model, "Exchange name");

            // Assert
            model.Received(1).ExchangeDeclare(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>(), Arg.Any <IDictionary <string, object> >());
            setup.Watcher.Received(1).Error(Arg.Any <Exception>());
        }
        public void Should_catch_all_other_error()
        {
            // Arrange
            var model = Substitute.For <IModel>();
            var setup = RabbitSetupForTest.CreateRabbitSetup(model);

            model.When(x => x.ExchangeDeclare(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>(), Arg.Any <IDictionary <string, object> >()))
            .Do(callInfo =>
            {
                throw new Exception();
            });

            // Action
            setup.DeclareExchange(new ExchangeSetupData(), model, "Exchange name");

            // Assert
            model.Received(1).ExchangeDeclare(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <bool>(), Arg.Any <bool>(), Arg.Any <IDictionary <string, object> >());
            setup.Watcher.Received(1).Error(Arg.Any <Exception>());
        }