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);
        }
示例#2
0
        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_not_declare_exchange_the_second_time_declare_is_called()
        {
            var exchangeDeclareCount = 0;

            var       publishExchangeDeclareStrategy = new Producer.PublishExchangeDeclareStrategy();
            var       advancedBus = Substitute.For <IAdvancedBus>();
            IExchange exchange    = new Exchange(exchangeName);

            advancedBus.ExchangeDeclare(exchangeName, "topic")
            .Returns(x =>
            {
                exchangeDeclareCount++;
                return(exchange);
            });

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

            advancedBus.Received().ExchangeDeclare(exchangeName, "topic");
            declaredExchange.ShouldBeTheSameAs(exchange);
            exchangeDeclareCount.ShouldEqual(1);
        }