Ejemplo n.º 1
0
        public void ShouldCallQueueDeclareAndQueueBindWhenPubSubTypeIsSubscribe()
        {
            const string queueName = "abc";
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                PubSubType = PubSubType.Subscribe,
                Subscription = new SubscriptionConfiguration()
                {
                    ExchangeBindings = new ExchangeBindingCollection()
                }
            };
            _endpoint.Subscription.ExchangeBindings.Add(
                new ExchangeBinding()
                    {
                        Name = "e1",
                        RoutingKey = "rk"
                    });
            _channel.Stub(x => x.QueueDeclare()).Return(new QueueDeclareOk(queueName, 1, 1));
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            _channel.AssertWasCalled(x => x.QueueDeclare());
            _channel.AssertWasCalled(x => x.QueueBind(
                queueName,
                _endpoint.Subscription.ExchangeBindings[0].Name,
                _endpoint.Subscription.ExchangeBindings[0].RoutingKey));
        }
Ejemplo n.º 2
0
        public void ShouldCallExchangeDeclarePubSubTypeIsSubscribeAndExchangeBindingShouldDeclare()
        {
            const string queueName = "abc";
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                PubSubType = PubSubType.Subscribe,
                Subscription = new SubscriptionConfiguration()
                {
                    ExchangeBindings = new ExchangeBindingCollection()
                }
            };
            _endpoint.Subscription.ExchangeBindings.Add(
                new ExchangeBinding()
                {
                    Name = "e1",
                    RoutingKey = "rk",
                    Type = ExchangeType.Direct,
                    DeclareExchange = true
                });
            _channel.Stub(x => x.QueueDeclare()).Return(new QueueDeclareOk(queueName, 1, 1));
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            var binding = _endpoint.Subscription.ExchangeBindings[0];
            _channel.AssertWasCalled(x => x.ExchangeDeclare(
                binding.Name,
                "direct"));
        }
Ejemplo n.º 3
0
        public void ShouldCallQueueDeclareWithParametersWhenPubSubTypeIsSubscribeAndRoutingKeyIsSet()
        {
            const string queueName = "abc";
            var expectedResult = new QueueDeclareOk(queueName, 1, 1);
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                Exchange = new ExchangeConfiguration() { Name = "ex1" },
                PubSubType = PubSubType.Subscribe,
                RoutingKey = queueName,
                Subscription = new SubscriptionConfiguration() { QueueName = "abckduf", NoAck = false }
            };
            _endpoint.Subscription.ExchangeBindings.Add(new ExchangeBinding() { Name = "e1" });
            _channel
                .Stub(x => x.QueueDeclare())
                .Return(new QueueDeclareOk(queueName, 1, 1));
            _channel
                .Stub(x => x.QueueDeclare(_endpoint.Subscription.QueueName, _endpoint.Subscription.NoAck, false, false, null))
                .Return(expectedResult);
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            _channel.AssertWasCalled(x => x.QueueDeclare(_endpoint.Subscription.QueueName, _endpoint.Subscription.Durable, false, false, null));
            _channel.AssertWasCalled(x => x.QueueBind(expectedResult, _endpoint.Subscription.ExchangeBindings[0].Name, ""));
        }
Ejemplo n.º 4
0
 public void ShouldThrowExceptionIfPubSubTypeIsSubscribeAndNoSubscriptionConfigExists()
 {
     const string queueName = "abc";
     var expectedResult = new QueueDeclareOk(queueName, 1, 1);
     _endpoint = new QueueEndpoint()
     {
         Name = "testendpoint",
         Exchange = new ExchangeConfiguration() { Name = "ex1" },
         PubSubType = PubSubType.Subscribe,
         RoutingKey = queueName,
         Subscription = null
     };
     var configurator = new ChannelConfigurator();
     configurator.ConfigureQueue(_endpoint, _channel);
 }
Ejemplo n.º 5
0
        public void ShouldNotCallQueueDeclareAndQueueBindWhenPubSubTypeIsPublish()
        {
            const string queueName = "abc";
            _endpoint = new QueueEndpoint()
            {
                Name = "testendpoint",
                Exchange = new ExchangeConfiguration() { Name = "ex1" },
                Subscription = new SubscriptionConfiguration() { QueueName = "asdf" },
                PubSubType = PubSubType.Publish
            };
            _channel.Stub(x => x.QueueDeclare()).Return(new QueueDeclareOk(queueName, 1, 1));
            var configurator = new ChannelConfigurator();
            configurator.ConfigureQueue(_endpoint, _channel);

            _channel.AssertWasNotCalled(x => x.QueueDeclare());
            _channel.AssertWasNotCalled(x => x.QueueBind(_endpoint.Subscription.QueueName, _endpoint.Exchange.Name, ""));
        }
Ejemplo n.º 6
0
 public void ShouldNotCallExchangeDeclareIfExchangesNameIsEmpty()
 {
     _endpoint = new QueueEndpoint()
     {
         Name = "testendpoint",
         Exchange = new ExchangeConfiguration() { Name = string.Empty, Type = ExchangeType.Fanout},
         PubSubType = PubSubType.Publish,
         RoutingKey = "asdf",
         Subscription = null
     };
     var configurator = new ChannelConfigurator();
     configurator.ConfigureQueue(_endpoint, _channel);
     _channel.AssertWasNotCalled(x => x.ExchangeDeclare(_endpoint.Exchange.Name, _endpoint.Exchange.Type.ToString().ToLower()));
 }