Example #1
0
        public void AddRabbitConnection_NoVCAPs_AddsConfiguredConnection()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();
            IConfigurationRoot config   = new ConfigurationBuilder().Build();

            // Act and Assert
            RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config);

            var service = services.BuildServiceProvider().GetService <ConnectionFactory>();

            Assert.NotNull(service);
        }
Example #2
0
        public void AddRabbitConnection_WithServiceName_NoVCAPs_ThrowsConnectorException()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();
            IConfigurationRoot config   = new ConfigurationBuilder().Build();

            // Act and Assert
            var ex =
                Assert.Throws <ConnectorException>(
                    () => RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config, "foobar"));

            Assert.Contains("foobar", ex.Message);
        }
Example #3
0
        public void AddRabbitConnection_ThrowsIfServiceNameNull()
        {
            // Arrange
            IServiceCollection services    = new ServiceCollection();
            IConfigurationRoot config      = null;
            string             serviceName = null;

            // Act and Assert
            var ex =
                Assert.Throws <ArgumentNullException>(
                    () => RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config, serviceName));

            Assert.Contains(nameof(serviceName), ex.Message);
        }
Example #4
0
        public void AddRabbitConnection_ThrowsIfServiceCollectionNull()
        {
            // Arrange
            IServiceCollection services = null;
            IConfigurationRoot config   = null;

            // Act and Assert
            var ex =
                Assert.Throws <ArgumentNullException>(
                    () => RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config));

            Assert.Contains(nameof(services), ex.Message);

            var ex2 =
                Assert.Throws <ArgumentNullException>(
                    () => RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config, "foobar"));

            Assert.Contains(nameof(services), ex2.Message);
        }
Example #5
0
        public void AddRabbitConnection_WithVCAPs_AddsRabbitConnection()
        {
            // Arrange
            var env1 = @"
{
      'limits': {
        'fds': 16384,
        'mem': 1024,
        'disk': 1024
      },
      'application_name': 'spring-cloud-broker',
      'application_uris': [
        'spring-cloud-broker.apps.testcloud.com'
      ],
      'name': 'spring-cloud-broker',
      'space_name': 'p-spring-cloud-services',
      'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae',
      'uris': [
        'spring-cloud-broker.apps.testcloud.com'
      ],
      'users': null,
      'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3',
      'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3',
      'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06'
    }
}";
            var env2 = @"
{
      'p-rabbitmq': [
        {
          'credentials': {
            'uri': 'amqp://*****:*****@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355'
          },
          'syslog_drain_url': null,
          'label': 'p-rabbitmq',
          'provider': null,
          'plan': 'standard',
          'name': 'myRabbitService',
          'tags': [
            'rabbitmq',
            'amqp'
          ]
        }
      ]
}
";
            // Arrange
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", env1);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", env2);

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddCloudFoundry();
            var config = builder.Build();

            // Act and Assert
            RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config);

            var service = services.BuildServiceProvider().GetService <ConnectionFactory>();

            Assert.NotNull(service);
            Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", service.VirtualHost);
            Assert.Equal(3306, service.Port);
            Assert.Equal("192.168.0.90", service.HostName);
            Assert.Equal("Dd6O1BPXUHdrmzbP", service.UserName);
            Assert.Equal("7E1LxXnlH2hhlPVt", service.Password);
        }
Example #6
0
        public void AddRabbitConnection_MultipleRabbitServices_ThrowsConnectorException()
        {
            // Arrange
            var env1 = @"
{
      'limits': {
        'fds': 16384,
        'mem': 1024,
        'disk': 1024
      },
      'application_name': 'spring-cloud-broker',
      'application_uris': [
        'spring-cloud-broker.apps.testcloud.com'
      ],
      'name': 'spring-cloud-broker',
      'space_name': 'p-spring-cloud-services',
      'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae',
      'uris': [
        'spring-cloud-broker.apps.testcloud.com'
      ],
      'users': null,
      'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3',
      'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3',
      'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06'
    }
}";
            var env2 = @"
{
      'p-rabbitmq': [
        {
            'credentials': {
                'uri': 'amqp://*****:*****@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355'
            },
          'syslog_drain_url': null,
          'label': 'p-rabbitmq',
          'provider': null,
          'plan': 'standard',
          'name': 'myRabbitService1',
          'tags': [
            'rabbitmq',
            'amqp'
          ]
        }, 
        {
            'credentials': {
                'uri': 'amqp://*****:*****@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355'
            },
          'syslog_drain_url': null,
          'label': 'p-Rabbit',
          'provider': null,
          'plan': 'standard',
          'name': 'myRabbitService2',
          'tags': [
            'rabbitmq',
            'amqp'
          ]
        } 
      ]
}
";
            // Arrange
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", env1);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", env2);

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddCloudFoundry();
            var config = builder.Build();

            // Act and Assert
            var ex =
                Assert.Throws <ConnectorException>(
                    () => RabbitProviderServiceCollectionExtensions.AddRabbitConnection(services, config));

            Assert.Contains("Multiple", ex.Message);
        }