Пример #1
0
            public void should_read_configuration_property()
            {
                const string endpointName  = "ep";
                const ushort prefetchCount = 5;
                const uint   prefetchSize  = 6;
                const string onKeyName     = "key";

                string Config =
                    $@"<endpoints>
                        <endpoint name=""{endpointName}"" connectionString=""amqp://localhost:666"">
                                <incoming>
                                    <on key=""{onKeyName}"" label=""msg.a"" react=""DynamicHandler"" requiresAccept=""true"">
                                        <qos prefetchCount=""{prefetchCount}"" prefetchSize=""{prefetchSize}"" />
                                    </on>
                                </incoming>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[endpointName];
                var elements = endpoint.Incoming.OfType <IncomingElement>();

                var on = elements.First(e => e.Key == onKeyName);

                on.Qos.PrefetchCount.Should().Be(prefetchCount, "Incoming QoS prefetch count should be set");
                on.Qos.PrefetchSize.Should().Be(prefetchSize, "Incoming QoS prefetch size should be set");
            }
Пример #2
0
            public void should_set_qos()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" lifecycleHandler=""ProducerHandler"">
                                <qos prefetchCount=""8"" />
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var busConfigurator = new BusConfiguration();

                busConfigurator.UseRabbitMq();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);
                var result  = sut.Configure("producer", busConfigurator);

                RabbitReceiverOptions rabbitReceiverOptions = ((BusConfiguration)result).ReceiverDefaults as RabbitReceiverOptions;

                Assert.IsNotNull(rabbitReceiverOptions, "Долны быть установлены настройки получателя.");
                Maybe <QoSParams> qosMaybe = rabbitReceiverOptions.GetQoS();

                Assert.IsTrue(qosMaybe.HasValue, "QoS должен быть установлен.");
                Assert.AreEqual(8, qosMaybe.Value.PrefetchCount, "Должно быть установлено количество потоков.");
            }
Пример #3
0
            public void should_receive()
            {
                string producerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""{0}{1}"">
                                <outgoing>
                                    <route key=""a"" label=""msg.a"" />
                                </outgoing>
                            </endpoint>
                        </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                string consumerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""consumer"" connectionString=""{0}{1}"">
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""BooTransformer"" type=""BooMessage"" />
                                </incoming>
                            </endpoint>
                        </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                var handler = new ConcreteTransformerOf <BooMessage>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IMessageOperator>().ToConstant(handler);

                kernel.Bind <IConsumerOf <BooMessage> >().To <OperatorConsumerOf <BooMessage> >()
                .InTransientScope()
                .Named("BooTransformer");


                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(consumerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("consumer", cfg);
                });

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                producer.Emit("msg.a", new { Num = 13 });

                handler.Received.WaitOne(5.Seconds())
                .Should()
                .BeTrue();
            }
Пример #4
0
            public void should_validate()
            {
                const string producerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"">
                                <outgoing>
                                    <route key=""a"" label=""msg.a"" />
                                </outgoing>
                            </endpoint>
                        </endpoints>";

                const string consumerConfig =
                    @"<endpoints>
                            <endpoint name=""consumer"" connectionString=""amqp://localhost/integration"">
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""BooHandler"" type=""BooMessage"" validate=""BooValidator"" />
                                </incoming>
                            </endpoint>
                        </endpoints>";

                var handler = new ConcreteHandlerOf <BooMessage>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IConsumerOf <BooMessage> >()
                .ToConstant(handler)
                .InSingletonScope()
                .Named("BooHandler");
                kernel.Bind <IMessageValidatorOf <BooMessage> >()
                .To <BooPayloadValidator>()
                .InSingletonScope()
                .Named("BooValidator");

                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(consumerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("consumer", cfg);
                });

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                producer.Emit("msg.a", new { Num = 13 });

                handler.Received.WaitOne(3.Seconds())
                .Should()
                .BeFalse();
            }
Пример #5
0
            public void should_read_handler_name()
            {
                const string config = @"<endpoints>
							<endpoint name=""Tester"" connectionString=""amqp://localhost:666"" lifecycleHandler=""handler"" />
						</endpoints>"                        ;

                var section = new XmlEndpointsSection(config);

                section.Endpoints["Tester"].LifecycleHandler.Should().
                Be("handler");
            }
Пример #6
0
            public void should_read_configuration_property()
            {
                const string config = @"<endpoints>
							<endpoint name=""Tester"" connectionString=""amqp://localhost:666"" />
						</endpoints>"                        ;

                var section = new XmlEndpointsSection(config);

                section.Endpoints["Tester"].ConnectionString.Should().
                Be("amqp://localhost:666");
            }
Пример #7
0
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"" faultQueueTtl=""00:10:00"">
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);

                Assert.AreEqual(TimeSpan.Parse("00:10:00"), section.Endpoints["a"].FaultQueueTtl, "Должно быть установлено время хранения сообщений в Fault очереди.");
            }
Пример #8
0
            public void should_use_default_value_if_not_set()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);

                Assert.IsNull(section.Endpoints["a"].FaultQueueLimit, "Время хранения сообщений в Fault очереди не должно быть установлено.");
            }
Пример #9
0
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"" parallelismLevel=""8"">
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);

                Assert.AreEqual(8, section.Endpoints["a"].ParallelismLevel, "Должно быть установлено количество обработчиков запроса.");
            }
Пример #10
0
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                            <qos prefetchCount=""8"" />
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);

                Assert.AreEqual(8, section.Endpoints["a"].Qos.PrefetchCount, "Должно быть установлено значение QoS.");
            }
Пример #11
0
            public void should_receive()
            {
                const string producerConfig = @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"">
                                <outgoing>
                                    <route key=""a"" label=""msg.a"" />
                                </outgoing>
                            </endpoint>
                        </endpoints>";

                const string consumerConfig =
                    @"<endpoints>
                            <endpoint name=""consumer"" connectionString=""amqp://localhost/integration"">
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""DynamicHandler"" />
                                </incoming>
                            </endpoint>
                        </endpoints>";

                var handler = new ConcreteHandlerOf <ExpandoObject>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IConsumerOf <ExpandoObject> >().
                ToConstant(handler).
                Named("DynamicHandler");

                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(consumerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("consumer", cfg);
                });

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                producer.Emit("msg.a", new { This = "That" });

                handler.Received.WaitOne(5.Seconds()).
                Should().
                BeTrue();
            }
Пример #12
0
            public void should_read_configuration_property()
            {
                const int queueLimit = 100;
                string    config     = string.Format(
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"" faultQueueLimit=""{0}"">
                        </endpoint>
                    </endpoints>",
                    queueLimit);

                var section = new XmlEndpointsSection(config);

                Assert.AreEqual(queueLimit, section.Endpoints["a"].FaultQueueLimit, "Должно быть установлено время хранения сообщений в Fault очереди.");
            }
Пример #13
0
            public void should_use_default_value_if_not_set()
            {
                const string Name   = "ep";
                string       config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString=""amqp://localhost:666"">
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(config);
                var property = section.Endpoints[Name].ReuseConnection;

                property.Should().BeTrue();
            }
Пример #14
0
            public void should_read_endpoint()
            {
                const string config = @"<endpoints>
							<endpoint name=""tester"" connectionString=""amqp://localhost:666"">
							</endpoint>
						</endpoints>"                        ;

                var section = new XmlEndpointsSection(config);

                section.Endpoints.Should().
                HaveCount(1);
                section.Endpoints["tester"].Should().
                NotBeNull();
            }
Пример #15
0
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                            <dynamic outgoing=""true"" />
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);

                Assert.IsNotNull(section.Endpoints["a"].Dynamic.Outgoing, "Должны быть добавлены установки динамической маршрутизации.");
                Assert.IsTrue(section.Endpoints["a"].Dynamic.Outgoing.Value, "Должна быть включена динамическая маршрутизация исходящих сообщений.");
            }
Пример #16
0
            public void should_read_configuration_property()
            {
                const string Name   = "ep";
                string       config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString=""amqp://localhost:666"" reuseConnection=""true"">
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(config);
                var property = section.Endpoints[Name].ReuseConnection;

                property.Should().HaveValue();
                property.Value.Should().BeTrue();
            }
            public void should_read_configuration_property()
            {
                const string config = @"<endpoints>
                            <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                                <caching enabled=""false"" />
                            </endpoint>
                            <endpoint name=""b"" connectionString=""amqp://localhost:777"">
                                <caching enabled=""true"" />
                            </endpoint>
                        </endpoints>";

                var section = new XmlEndpointsSection(config);

                section.Endpoints["a"].Caching.Enabled.Should().
                    BeFalse();
                section.Endpoints["b"].Caching.Enabled.Should().
                    BeTrue();
            }
Пример #18
0
            public void should_route_any()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" >
                                <dynamic outgoing=""true"" />
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);

                using (var bus = new BusFactory().Create(cfg => sut.Configure("producer", cfg), false))
                {
                    Assert.IsTrue(bus.CanRoute(MessageLabel.Any), "Должна быть включена динамическая маршрутизация.");
                }
            }
Пример #19
0
            public void should_read_configuration_property()
            {
                const string config = @"<endpoints>
							<endpoint name=""a"" connectionString=""amqp://localhost:666"">
								<caching enabled=""false"" />
							</endpoint>
							<endpoint name=""b"" connectionString=""amqp://localhost:777"">
								<caching enabled=""true"" />
							</endpoint>
						</endpoints>"                        ;

                var section = new XmlEndpointsSection(config);

                section.Endpoints["a"].Caching.Enabled.Should().
                BeFalse();
                section.Endpoints["b"].Caching.Enabled.Should().
                BeTrue();
            }
Пример #20
0
            public void should_not_be_set_by_default()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"">
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var busConfigurator = new BusConfiguration();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);
                var result  = sut.Configure("producer", busConfigurator);

                ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults;

                Assert.IsFalse(receiverOptions.GetFaultQueueTtl().HasValue, "Не должно быть установлено время хранения сообщений.");
            }
Пример #21
0
            public void should_use_default_value_if_not_set()
            {
                const string Name   = "ep";
                string       Config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString="""">
                                <incoming>
                                    <on key=""key"" label=""label"" react=""reactor"" requiresAccept=""true"" >
                                    </on>
                                </incoming>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[Name];
                var elements = endpoint.Incoming.OfType <IncomingElement>();
                var property = elements.First().ReuseConnection;

                property.Should().NotHaveValue();
            }
Пример #22
0
            public void should_read_configuration_property()
            {
                const string Name   = "ep";
                string       Config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString="""">
                                <outgoing>
                                    <route key=""key"" label=""label"" connectionString=""amqp://localhost:999"">
									</route>
                                </outgoing>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[Name];
                var elements = endpoint.Outgoing.OfType <OutgoingElement>();
                var property = elements.First().ConnectionString;

                property.Should().NotBeNullOrEmpty();
            }
Пример #23
0
            public void should_use_default_value_if_not_set()
            {
                const string Name   = "ep";
                string       Config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString="""">
                                <outgoing>
                                    <route key=""key"" label=""label"">
									</route>
                                </outgoing>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[Name];
                var elements = endpoint.Outgoing.OfType <OutgoingElement>();
                var property = elements.First().ReuseConnection;

                property.Should().NotHaveValue();
            }
Пример #24
0
            public void should_set_queue_ttl()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" faultQueueTtl=""10:10:00"">
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var busConfigurator = new BusConfiguration();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);
                var result  = sut.Configure("producer", busConfigurator);

                ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults;

                Assert.IsTrue(receiverOptions.GetFaultQueueTtl().HasValue, "Должно быть установлено время хранения сообщений.");
                Assert.AreEqual(TimeSpan.Parse("10:10:00"), receiverOptions.GetFaultQueueTtl().Value, "Должно быть устрановлено корректное время хранения.");
            }
Пример #25
0
            public void should_read_configuration_property()
            {
                const string Name   = "ep";
                string       Config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString="""">
                                <incoming>
                                    <on key=""key"" label=""label"" react=""reactor"" requiresAccept=""true"" connectionString=""amqp://localhost:777"">
                                    </on>
                                </incoming>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[Name];
                var elements = endpoint.Incoming.OfType <IncomingElement>();
                var property = elements.First().ConnectionString;

                property.Should().NotBeNullOrEmpty();
            }
Пример #26
0
            public void should_handle_state_changes()
            {
                string producerConfig = string.Format(
                    @"<endpoints>
                        <endpoint name=""producer"" connectionString=""{0}{1}"" lifecycleHandler=""ProducerHandler"">
                            <outgoing>
                                <route key=""a"" label=""msg.a"" />
                            </outgoing>
                        </endpoint>
                    </endpoints>",
                    this.AmqpConnection,
                    this.VhostName);

                var handler = new Mock <IBusLifecycleHandler>();

                IKernel kernel = new StandardKernel();

                kernel.Bind <IBusLifecycleHandler>().
                ToConstant(handler.Object).
                Named("ProducerHandler");

                DependencyResolverFunc dependencyResolver = (name, type) => kernel.Get(type, name);

                IBus producer = this.StartBus(
                    "producer",
                    cfg =>
                {
                    var section = new XmlEndpointsSection(producerConfig);
                    new AppConfigConfigurator(section, dependencyResolver).Configure("producer", cfg);
                });

                handler.Verify(h => h.OnStarting(It.IsAny <IBus>(), It.IsAny <EventArgs>()), Times.Once);
                handler.Verify(h => h.OnStarted(It.IsAny <IBus>(), It.IsAny <EventArgs>()), Times.Once);
                handler.Verify(h => h.OnStopping(It.IsAny <IBus>(), It.IsAny <EventArgs>()), Times.Never);
                handler.Verify(h => h.OnStopped(It.IsAny <IBus>(), It.IsAny <EventArgs>()), Times.Never);

                producer.Stop();

                handler.Verify(h => h.OnStopping(It.IsAny <IBus>(), It.IsAny <EventArgs>()), Times.Once);
                handler.Verify(h => h.OnStopped(It.IsAny <IBus>(), It.IsAny <EventArgs>()), Times.Once);
            }
Пример #27
0
            public void should_read_configuration_property()
            {
                const string Name   = "ep";
                string       Config =
                    $@"<endpoints>
                        <endpoint name=""{Name}"" connectionString="""">
                                <outgoing>
                                    <route key=""key"" label=""label"" reuseConnection=""true"">
									</route>
                                </outgoing>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[Name];
                var elements = endpoint.Outgoing.OfType <OutgoingElement>();
                var property = elements.First().ReuseConnection;

                property.Should().HaveValue();
                property.Should().BeTrue();
            }
Пример #28
0
            public void should_be_default()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" lifecycleHandler=""ProducerHandler"">
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);

                using (var bus = new BusFactory().Create(cfg => sut.Configure("producer", cfg), false))
                {
                    RabbitReceiverOptions rabbitReceiverOptions = ((BusConfiguration)bus.Configuration).ReceiverDefaults as RabbitReceiverOptions;
                    Assert.IsNotNull(rabbitReceiverOptions, "Долны быть установлены настройки получателя.");
                    Maybe <QoSParams> qosMaybe = rabbitReceiverOptions.GetQoS();
                    Assert.IsTrue(qosMaybe.HasValue, "QoS должен быть установлен.");
                    Assert.AreEqual(50, qosMaybe.Value.PrefetchCount, "Должно быть установлено количество потоков.");
                }
            }
Пример #29
0
            public void should_set_queue_limit()
            {
                const int queueLimit     = 100;
                string    producerConfig = string.Format(
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" faultQueueLimit=""{0}"">
                            </endpoint>
                        </endpoints>",
                    queueLimit);

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var busConfigurator = new BusConfiguration();

                var section = new XmlEndpointsSection(producerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);
                var result  = sut.Configure("producer", busConfigurator);

                ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults;

                Assert.IsTrue(receiverOptions.GetFaultQueueLimit().HasValue, "Должно быть установлено максимальное количество сообщений.");
                Assert.AreEqual(queueLimit, receiverOptions.GetFaultQueueLimit().Value, "Должно быть устрановлено корректное максимальное количество сообщений.");
            }
Пример #30
0
            public void should_use_default_value_if_not_set()
            {
                const string endpointName = "ep";
                const string onKeyName    = "key";

                string Config =
                    $@"<endpoints>
                        <endpoint name=""{endpointName}"" connectionString=""amqp://localhost:666"">
                                <incoming>
                                    <on key=""{onKeyName}"" label=""msg.a"" react=""DynamicHandler"" requiresAccept=""true"" >
                                    </on>
                                </incoming>
                        </endpoint>
                    </endpoints>";

                var section  = new XmlEndpointsSection(Config);
                var endpoint = section.Endpoints[endpointName];
                var elements = endpoint.Incoming.OfType <IncomingElement>();

                var on = elements.First(e => e.Key == onKeyName);

                on.ParallelismLevel.Should().BeNull("Incoming parallelism level should not be set");
            }
Пример #31
0
            public void should_set_parallelismLevel()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" parallelismLevel=""8"">
                                <qos prefetchCount=""8"" />
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var busConfigurator = new BusConfiguration();

                busConfigurator.UseRabbitMq();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);
                var result  = sut.Configure("producer", busConfigurator);

                ReceiverOptions receiverOptions = ((BusConfiguration)result).ReceiverDefaults;

                Assert.IsTrue(receiverOptions.GetParallelismLevel().HasValue, "Должно быть установлено количество обработчиков.");
                Assert.AreEqual(8, receiverOptions.GetParallelismLevel().Value, "Должно быть установлено количество обработчиков.");
            }
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"" faultQueueTtl=""00:10:00"">
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);
                Assert.AreEqual(TimeSpan.Parse("00:10:00"), section.Endpoints["a"].FaultQueueTtl, "Должно быть установлено время хранения сообщений в Fault очереди.");
            }
            public void should_read_connection_string()
            {
                const string config = @"<endpoints>
                            <endpoint name=""Tester"" connectionString=""amqp://localhost:666"" />
                        </endpoints>";

                var section = new XmlEndpointsSection(config);

                section.Endpoints["Tester"].ConnectionString.Should().
                    Be("amqp://localhost:666");
            }
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                            <qos prefetchCount=""8"" />
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);
                Assert.AreEqual(8, section.Endpoints["a"].Qos.PrefetchCount, "Должно быть установлено значение QoS.");
            }
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                            <dynamic outgoing=""true"" />
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);
                Assert.IsNotNull(section.Endpoints["a"].Dynamic.Outgoing, "Должны быть добавлены установки динамической маршрутизации.");
                Assert.IsTrue(section.Endpoints["a"].Dynamic.Outgoing.Value, "Должна быть включена динамическая маршрутизация исходящих сообщений.");
            }
            public void should_read_configuration_property()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"" parallelismLevel=""8"">
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);
                Assert.AreEqual(8, section.Endpoints["a"].ParallelismLevel, "Должно быть установлено количество обработчиков запроса.");
            }
            public void should_read_endpoints()
            {
                const string config = @"<endpoints>
                            <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                            </endpoint>
                            <endpoint name=""b"" connectionString=""amqp://localhost:777"">
                            </endpoint>
                        </endpoints>";

                var section = new XmlEndpointsSection(config);

                section.Endpoints.Should().
                    HaveCount(2);
                section.Endpoints["a"].Should().
                    NotBeNull();
                section.Endpoints["b"].Should().
                    NotBeNull();
            }
            public void should_use_default_value_if_not_set()
            {
                const string Config =
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"">
                        </endpoint>
                    </endpoints>";

                var section = new XmlEndpointsSection(Config);
                Assert.IsNull(section.Endpoints["a"].FaultQueueTtl, "Время хранения сообщений в Fault очереди не должно быть установлено.");
            }
            public void should_read_handler_name()
            {
                const string config = @"<endpoints>
                            <endpoint name=""Tester"" connectionString=""amqp://localhost:666"" lifecycleHandler=""handler"" />
                        </endpoints>";

                var section = new XmlEndpointsSection(config);

                section.Endpoints["Tester"].LifecycleHandler.Should().
                    Be("handler");
            }
            public void should_read_configuration_property()
            {
                const int queueLimit = 100;
                string config = string.Format(
                    @"<endpoints>
                        <endpoint name=""a"" connectionString=""amqp://localhost:666"" faultQueueLimit=""{0}"">
                        </endpoint>
                    </endpoints>",
                    queueLimit);

                var section = new XmlEndpointsSection(config);
                Assert.AreEqual(queueLimit, section.Endpoints["a"].FaultQueueLimit, "Должно быть установлено время хранения сообщений в Fault очереди.");
            }
            public void should_read_everything()
            {
                const string config = @"<endpoints>
                            <endpoint name=""tester"" connectionString=""amqp://localhost:666"">
                                <incoming>
                                    <on key=""a"" label=""msg.a"" react=""DynamicHandler"" requiresAccept=""true"" />
                                    <on key=""b"" label=""msg.b"" react=""TransformB"" />
                                </incoming>
                                <outgoing>
                                    <route key=""a"" label=""msg.out.a"" persist=""true"">
                                        <callbackEndpoint default=""true"" />
                                    </route>
                                </outgoing>
                            </endpoint>
                        </endpoints>";

                var section = new XmlEndpointsSection(config);

                section.Endpoints.Should().
                    HaveCount(1);

                EndpointElement endpoint = section.Endpoints["tester"];
                endpoint.Incoming.Should().
                    HaveCount(2);
                endpoint.Outgoing.Should().
                    HaveCount(1);

                List<IncomingElement> incoming = endpoint.Incoming.OfType<IncomingElement>().
                    ToList();

                incoming[0].RequiresAccept.Should().
                    BeTrue();
                incoming[1].RequiresAccept.Should().
                    BeFalse();
            }