Esempio n. 1
0
        public void AssignHostAddress_DefaultPort_PropertiesAreValid()
        {
            var options = new ActiveMqOptions
            {
                HostAddress = new Uri("activemq://localhost:61616")
            };

            Assert.Equal("localhost", options.Host);
            Assert.Equal(61616, options.Port);
        }
Esempio n. 2
0
        public void AssignProperties_HostAddressIsValid()
        {
            var options = new ActiveMqOptions
            {
                Host = "localhost",
                Port = 8080,
            };

            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Equal(8080, options.HostAddress.Port);
        }
Esempio n. 3
0
        public void AssignHostAddress_EmptyPort_PropertiesAreValid()
        {
            var options = new ActiveMqOptions
            {
                HostAddress = new Uri("activemq://localhost")
            };

            Assert.Equal("localhost", options.Host);
            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Null(options.Port);
        }
Esempio n. 4
0
        public void DefaultCtor_IsValid()
        {
            var options = new ActiveMqOptions();

            Assert.Equal(string.Empty, options.ConnectionName);
            Assert.Equal(new Uri("activemq:/"), options.HostAddress);
            Assert.Null(options.Host);
            Assert.Null(options.Port);
            Assert.Null(options.Username);
            Assert.Null(options.Password);
        }
Esempio n. 5
0
        public void AssignHostAddress_OtherPort_PropertiesAreValid()
        {
            var options = new ActiveMqOptions
            {
                HostAddress = new Uri("activemq://localhost:8080/")
            };

            Assert.Equal("localhost", options.Host);
            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Equal(8080, options.Port);
        }
Esempio n. 6
0
        public void AssignDefaultPort_WithoutSsl_HostAddressIsValid()
        {
            var options = new ActiveMqOptions
            {
                Host = "localhost",
                Port = 61616,
            };

            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Equal(61616, options.HostAddress.Port);
        }
Esempio n. 7
0
        public void AssignZeroPort_HostAddressIsValid()
        {
            var options = new ActiveMqOptions
            {
                Host = "localhost",
                Port = 0,
            };

            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Equal(-1, options.HostAddress.Port);
        }
Esempio n. 8
0
        public void AssignOtherPort_WithSsl_HostAddressIsValid()
        {
            var options = new ActiveMqOptions
            {
                Host   = "localhost",
                Port   = 8080,
                UseSsl = true,
            };

            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Equal(8080, options.HostAddress.Port);
        }
Esempio n. 9
0
        public void AssignNullPort_WithSsl_HostAddressIsValid()
        {
            var options = new ActiveMqOptions
            {
                Host   = "localhost",
                Port   = null,
                UseSsl = true,
            };

            Assert.Equal("localhost", options.HostAddress.Host);
            Assert.Equal(61617, options.HostAddress.Port);
        }
        public async Task UseActiveMq_GivenStaticOptions_ThenValid()
        {
            var options = new ActiveMqOptions
            {
                ConnectionName = "connection-name-test",
                Host           = "127.0.0.1",
                Port           = 61616,
                Username       = "******",
                Password       = "******",
            };

            var mockBusHandle                      = new Mock <BusHandle>(MockBehavior.Strict);
            var mockBusControl                     = new Mock <IBusControl>(MockBehavior.Strict);
            var mockActiveMqBusFactory             = new Mock <IBusFactory <IActiveMqBusFactoryConfigurator> >(MockBehavior.Strict);
            var mockActiveMqBusFactoryConfigurator = new Mock <IActiveMqBusFactoryConfigurator>(MockBehavior.Strict);
            var mockActiveMqHost                   = new Mock <IActiveMqHost>(MockBehavior.Strict);

            mockBusControl
            .Setup(_ => _.StartAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(mockBusHandle.Object)
            .Verifiable();

            mockBusControl
            .Setup(_ => _.StopAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            mockActiveMqBusFactory
            .Setup(_ => _.Create(It.IsAny <Action <IActiveMqBusFactoryConfigurator> >()))
            .Callback((Action <IActiveMqBusFactoryConfigurator> configure) => configure(mockActiveMqBusFactoryConfigurator.Object))
            .Returns(mockBusControl.Object)
            .Verifiable();

            mockActiveMqBusFactoryConfigurator
            .Setup(_ => _.Host(It.IsAny <ActiveMqHostSettings>()))
            .Callback((ActiveMqHostSettings settings) =>
            {
                Assert.Equal(options.Host, settings.Host);
                Assert.Equal(options.Port, settings.Port);
                Assert.Equal(options.Username, settings.Username);
                Assert.Equal(options.Password, settings.Password);
            })
            .Returns(mockActiveMqHost.Object)
            .Verifiable();

            var services = new ServiceCollection();

            services.AddSingleton(mockActiveMqBusFactory.Object);

            services.AddLogging(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Trace);
                builder.AddXUnit(_output);
            });

            services.AddMassTransit(builder =>
            {
                builder.UseActiveMq(options);
            });

            using (var serviceProvider = services.BuildServiceProvider())
            {
                var busManager = serviceProvider.GetRequiredService <IBusManager>();

                await busManager.StartAsync(CancellationToken.None).ConfigureAwait(false);

                var bus = busManager.GetBus(options.ConnectionName);
                Assert.NotNull(bus);

                await busManager.StopAsync(CancellationToken.None).ConfigureAwait(false);
            }

            mockActiveMqHost.Verify();
            mockActiveMqBusFactoryConfigurator.Verify();
            mockActiveMqBusFactory.Verify();
            mockBusControl.Verify();
            mockBusHandle.Verify();
        }