public void Should_declare_exchange_again_if_first_attempt_failed()
        {
            var exchangeDeclareCount = 0;
           
            var advancedBus = MockRepository.GenerateStrictMock<IAdvancedBus>();
            IExchange exchange = new Exchange(exchangeName);

            advancedBus
                .Expect(x => x.ExchangeDeclare(exchangeName, "topic"))
                .Throw(new Exception())
                .WhenCalled(x => exchangeDeclareCount++);

            advancedBus
                .Expect(x => x.ExchangeDeclare(exchangeName, "topic"))
                .Return(exchange)
                .WhenCalled(x => exchangeDeclareCount++);

            var publishExchangeDeclareStrategy = new VersionedPublishExchangeDeclareStrategy();
            try
            {
                publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName, ExchangeType.Topic);
            }
            catch (Exception)
            {
            }
            var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName, ExchangeType.Topic);
            advancedBus.AssertWasCalled(x => x.ExchangeDeclare(exchangeName, "topic"));
            advancedBus.AssertWasCalled(x => x.ExchangeDeclare(exchangeName, "topic"));
            declaredExchange.ShouldBeTheSameAs(exchange);
            exchangeDeclareCount.ShouldEqual(1);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var exchange = new Exchange("my_exchange");
            advancedBus.ExchangeDelete(exchange);
        }
        public void PublishToAnExchange()
        {
            var exchange = new Exchange("my_exchange");

            var body = Encoding.UTF8.GetBytes("Hello World!");
            advancedBus.Publish(exchange, "routing_key", false, false, new MessageProperties(), body);

            Thread.Sleep(5000);
        }
        public void PublishToAnExchange()
        {
            var exchange = new Exchange("my_exchange");

            using (var channel = advancedBus.OpenPublishChannel())
            {
                var body = Encoding.UTF8.GetBytes("Hello World!");
                channel.Publish(exchange, "routing_key", new MessageProperties(), body);
            }

            Thread.Sleep(500);
        }
        public void Should_not_declare_exchange_the_second_time_declare_is_called()
        {
            var exchangeDeclareCount = 0;

            var publishExchangeDeclareStrategy = new Producer.PublishExchangeDeclareStrategy();
            var advancedBus = MockRepository.GenerateStub<IAdvancedBus>();
            IExchange exchange = new Exchange(exchangeName);
            advancedBus
                .Stub(x => x.ExchangeDeclare(exchangeName, "topic"))
                .Return(exchange)
                .WhenCalled(x => exchangeDeclareCount++);
            var _ = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName, ExchangeType.Topic);
            var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName, ExchangeType.Topic);

            advancedBus.AssertWasCalled(x => x.ExchangeDeclare(exchangeName, "topic"));
            declaredExchange.ShouldBeTheSameAs(exchange);
            exchangeDeclareCount.ShouldEqual(1);
        }
        public void Should_declare_exchange_the_first_time_declare_is_called()
        {
            var exchangeDeclareCount = 0;

            var publishExchangeDeclareStrategy = new PublishExchangeDeclareStrategy();
            var advancedBus = MockRepository.GenerateStub<IAdvancedBus>();
            IExchange exchange = new Exchange(exchangeName);
            var exchangeTask = TaskHelpers.FromResult(exchange);
            advancedBus
                .Stub(x => x.ExchangeDeclareAsync(exchangeName, "topic"))
                .Return(exchangeTask)
                .WhenCalled(x => exchangeDeclareCount++);

            var declaredExchange = publishExchangeDeclareStrategy.DeclareExchange(advancedBus, exchangeName, ExchangeType.Topic);

            advancedBus.AssertWasCalled(x => x.ExchangeDeclareAsync(exchangeName, "topic"));
            declaredExchange.ShouldBeTheSameAs(exchange);
            exchangeDeclareCount.ShouldEqual(1);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var exchange = new Exchange("my_exchange");
            var queue = new Topology.Queue("my_queue", false);
            binding = advancedBus.Bind(exchange, queue, "my_routing_key");
            advancedBus.BindingDelete(binding);
        }