Example #1
0
        private void VerifyBuild()
        {
            subject.SetExchange(expectedExchange);

            subject.ExchangeType   = expectedType;
            subject.Durable        = expectedDurable;
            subject.AutoDelete     = expectedAutoDelete;
            subject.QueueExclusive = expectedExclusive;

            var actual = subject.Build();

            Assert.IsNotNull(actual);


            // mockChannel.Verify(c => c.ExchangeDeclarePassive(expectedExchange));

            mockChannel.Verify(c => c.ExchangeDeclare(expectedExchange,
                                                      expectedType.ToString(),
                                                      expectedDurable,
                                                      expectedAutoDelete,
                                                      expectedArguments));

            mockChannel.Verify(c => c.BasicQos(0, expectedPreFetchLimit, false));

            mockChannel.Verify(c => c.QueueDeclare(expectedQueue, expectedDurable,
                                                   expectedExclusive, expectedAutoDelete, expectedArguments), Times.Never);
        }
        private void VerifyBuild()
        {
            subject.SetExchange(expectedExchange);
            subject.AddQueue(expectedTuple.Item1, expectedTuple.Item2);

            subject.ExchangeType   = expectedType;
            subject.Durable        = expectedDurable;
            subject.AutoDelete     = expectedAutoDelete;
            subject.QueueExclusive = expectedExclusive;


            var actual = subject.Build();

            Assert.IsNotNull(actual);

            mockConnectionCreator.Verify(creator => creator.GetConnection());

            mockModel.Verify(c => c.ExchangeDeclare(expectedExchange,
                                                    expectedType.ToString(),
                                                    expectedDurable,
                                                    expectedAutoDelete,
                                                    expectedExchangeArguments));

            mockModel.Verify(c => c.BasicQos(0, expectedPreFetchLimit, false));

            mockModel.Verify(c => c.QueueDeclare(expectedQueue, expectedDurable,
                                                 expectedExclusive, expectedAutoDelete, expectedQueueArguments));


            mockModel.Verify(c => c.QueueBind(expectedQueue, expectedExchange, expectedRoutingKey, null));
        }
        /// <summary>
        /// 定义交换机
        /// </summary>
        /// <param name="name">交换机名称</param>
        /// <param name="type">交换机类型</param>
        /// <param name="alternateExchangeName">当消息投递不成功时的转发到的备用交换机名称(由此交换机进行转投)</param>
        /// <param name="arguments">其它参数</param>
        public void ExchangeDeclare(string name, RabbitExchangeType type, string alternateExchangeName = null, IDictionary <string, object> arguments = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (!string.IsNullOrEmpty(alternateExchangeName))
            {
                if (arguments == null)
                {
                    arguments = new Dictionary <string, object>();
                }
                string altKey = "alternate-exchange";
                arguments[altKey] = alternateExchangeName;
            }

            ManageChannel.ExchangeDeclare(name, type.ToString().ToLower(), true, false, arguments);
        }