public void AddPostgresConnection_WithCruncyVCAPs_AddsPostgresConnection()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", PostgresTestHelpers.SingleServerVCAP_Crunchy);
            var appsettings = new Dictionary <string, string>()
            {
                ["postgres:client:urlEncodedCredentials"] = "true"
            };

            var builder = new ConfigurationBuilder();

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

            // Act and Assert
            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);

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

            Assert.NotNull(service);
            var connString = service.ConnectionString;

            Assert.Contains("Host=10.194.45.174;", connString);
            Assert.Contains("Port=5432;", connString);
            Assert.Contains("Database=postgresample;", connString);
            Assert.Contains("Username=steeltoe7b59f5b8a34bce2a3cf873061cfb5815;", connString);
            Assert.Contains("Password=!DQ4Wm!r4omt$h1929!$;", connString);
        }
        public void AddPostgresConnection_WithVCAPs_AddsPostgresConnection()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", PostgresTestHelpers.SingleServerVCAP_EDB);
            var builder = new ConfigurationBuilder();

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

            // Act and Assert
            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);

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

            Assert.NotNull(service);
            var connString = service.ConnectionString;

            Assert.Contains("1e9e5dae-ed26-43e7-abb4-169b4c3beaff", connString);
            Assert.Contains("5432", connString);
            Assert.Contains("postgres.testcloud.com", connString);
            Assert.Contains("lmu7c96mgl99b2t1hvdgd5q94v", connString);
            Assert.Contains("1e9e5dae-ed26-43e7-abb4-169b4c3beaff", connString);
        }
        public void AddPostgresConnection_WithAzureVCAPs_AddsPostgresConnection()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", PostgresTestHelpers.SingleServerVCAP_Azure);
            var appsettings = new Dictionary <string, string>()
            {
                ["postgres:client:urlEncodedCredentials"] = "true"
            };

            var builder = new ConfigurationBuilder();

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

            // Act and Assert
            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);

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

            Assert.NotNull(service);
            var connString = service.ConnectionString;

            Assert.Contains("Host=2980cfbe-e198-46fd-8f81-966584bb4678.postgres.database.azure.com;", connString);
            Assert.Contains("Port=5432;", connString);
            Assert.Contains("Database=g01w0qnrb7;", connString);
            Assert.Contains("Username=c2cdhwt4nd@2980cfbe-e198-46fd-8f81-966584bb4678;", connString);
            Assert.Contains("Password=Dko4PGJAsQyEj5gj;", connString);
        }
Exemplo n.º 4
0
        public void AddPostgresConnection_WithServiceName_NoVCAPs_ThrowsConnectorException()
        {
            IServiceCollection services = new ServiceCollection();
            var config = new ConfigurationBuilder().Build();

            var ex = Assert.Throws <ConnectorException>(() => PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config, "foobar"));

            Assert.Contains("foobar", ex.Message);
        }
Exemplo n.º 5
0
        public void AddPostgresConnection_ThrowsIfServiceNameNull()
        {
            IServiceCollection services    = new ServiceCollection();
            IConfigurationRoot config      = null;
            string             serviceName = null;

            var ex = Assert.Throws <ArgumentNullException>(() => PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config, serviceName));

            Assert.Contains(nameof(serviceName), ex.Message);
        }
Exemplo n.º 6
0
        public void AddPostgresConnection_NoVCAPs_AddsPostgresConnection()
        {
            IServiceCollection services = new ServiceCollection();
            var config = new ConfigurationBuilder().Build();

            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);

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

            Assert.NotNull(service);
        }
Exemplo n.º 7
0
        public void AddPostgresConnection_NoVCAPs_AddsPostgresConnection()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();
            IConfigurationRoot config   = new ConfigurationBuilder().Build();

            // Act and Assert
            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);

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

            Assert.NotNull(service);
        }
Exemplo n.º 8
0
        public void AddPostgresConnection_ThrowsIfConfigurationNull()
        {
            IServiceCollection services = new ServiceCollection();
            IConfigurationRoot config   = null;

            var ex = Assert.Throws <ArgumentNullException>(() => PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config));

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

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

            Assert.Contains(nameof(config), ex2.Message);
        }
Exemplo n.º 9
0
        public void AddPosgreSqlConnection_AddsRelationalHealthContributor()
        {
            IServiceCollection services = new ServiceCollection();
            var builder = new ConfigurationBuilder();

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

            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);
            var healthContributor = services.BuildServiceProvider().GetService <IHealthContributor>() as RelationalDbHealthContributor;

            Assert.NotNull(healthContributor);
        }
Exemplo n.º 10
0
        public void AddPostgresConnection_MultiplePostgresServices_ThrowsConnectorException()
        {
            IServiceCollection services = new ServiceCollection();

            Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION);
            Environment.SetEnvironmentVariable("VCAP_SERVICES", PostgresTestHelpers.TwoServerVCAP_EDB);

            var builder = new ConfigurationBuilder();

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

            var ex = Assert.Throws <ConnectorException>(() => PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config));

            Assert.Contains("Multiple", ex.Message);
        }
Exemplo n.º 11
0
        public void AddPosgreSqlConnection_AddsRelationalHealthContributor_WhenCommunityHealthCheckExistsAndForced()
        {
            IServiceCollection services = new ServiceCollection();
            var builder = new ConfigurationBuilder();

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

            var cm = new ConnectionStringManager(config);
            var ci = cm.Get <PostgresConnectionInfo>();

            services.AddHealthChecks().AddNpgSql(ci.ConnectionString, name: ci.Name);

            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config, addSteeltoeHealthChecks: true);
            var healthContributor = services.BuildServiceProvider().GetService <IHealthContributor>() as RelationalDbHealthContributor;

            Assert.NotNull(healthContributor);
        }
        public void AddPosgreSqlConnection_DoesntAddRelationalHealthContributor_WhenCommunityHealthCheckExists()
        {
            // Arrange
            IServiceCollection services = new ServiceCollection();
            var builder = new ConfigurationBuilder();

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

            var cm = new ConnectionStringManager(config);
            var ci = cm.Get <PostgresConnectionInfo>();

            services.AddHealthChecks().AddNpgSql(ci.ConnectionString, name: ci.Name);

            // Act
            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);
            var healthContributor = services.BuildServiceProvider().GetService <IHealthContributor>() as RelationalHealthContributor;

            // Assert
            Assert.Null(healthContributor);
        }
Exemplo n.º 13
0
        public void AddPostgresConnection_WithVCAPs_AddsPostgresConnection()
        {
            // 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 = @"
{
        'EDB-Shared-PostgreSQL': [
            {
                'credentials': {
                    'uri': 'postgres://*****:*****@postgres.testcloud.com:5432/1e9e5dae-ed26-43e7-abb4-169b4c3beaff'
                },
            'syslog_drain_url': null,
            'label': 'EDB-Shared-PostgreSQL',
            'provider': null,
            'plan': 'Basic PostgreSQL Plan',
            'name': 'myPostgres',
            'tags': [
                'PostgreSQL',
                'Database storage'
            ]
        }
      ]
}
";
            // 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
            PostgresProviderServiceCollectionExtensions.AddPostgresConnection(services, config);

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

            Assert.NotNull(service);
            var connString = service.ConnectionString;

            Assert.True(connString.Contains("1e9e5dae-ed26-43e7-abb4-169b4c3beaff"));
            Assert.True(connString.Contains("5432"));
            Assert.True(connString.Contains("postgres.testcloud.com"));
            Assert.True(connString.Contains("lmu7c96mgl99b2t1hvdgd5q94v"));
            Assert.True(connString.Contains("1e9e5dae-ed26-43e7-abb4-169b4c3beaff"));
        }