├── .appveyor.yml ├── .gitattributes ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── Connectors.sln ├── License.txt ├── README.md ├── config ├── versions-dev.props ├── versions-master.props └── versions.props ├── localSql.cmd ├── nuget.config ├── open_source_licenses.txt ├── src ├── Steeltoe.CloudFoundry.Connector.EF6Autofac │ ├── MySqlDbContextContainerBuilderExtensions.cs │ ├── SqlServerDbContextContainerBuilderExtensions.cs │ └── Steeltoe.CloudFoundry.Connector.EF6Autofac.csproj ├── Steeltoe.CloudFoundry.Connector.EF6Core │ ├── MySqlDbContextServiceCollectionExtensions.cs │ ├── SqlServerDbContextServiceCollectionExtensions.cs │ └── Steeltoe.CloudFoundry.Connector.EF6Core.csproj ├── Steeltoe.CloudFoundry.Connector.EFCore │ ├── EntityFrameworkCoreTypeLocator.cs │ ├── MigrateDbContextTask.cs │ ├── MySqlDbContextOptionsExtensions.cs │ ├── PostgresDbContextOptionsExtensions.cs │ ├── SqlServerDbContextOptionsExtensions.cs │ └── Steeltoe.CloudFoundry.Connector.EFCore.csproj ├── Steeltoe.CloudFoundry.ConnectorAutofac │ ├── HystrixContainerBuilderExtensions.cs │ ├── MongoDbContainerBuilderExtensions.cs │ ├── MySqlContainerBuilderExtensions.cs │ ├── OAuthContainerBuilderExtensions.cs │ ├── PostgreSqlContainerBuilderExtensions.cs │ ├── RabbitMQContainerBuilderExtensions.cs │ ├── RedisContainerBuilderExtensions.cs │ ├── SqlServerContainerBuilderExtensions.cs │ └── Steeltoe.CloudFoundry.ConnectorAutofac.csproj ├── Steeltoe.CloudFoundry.ConnectorBase │ ├── AbstractServiceConnectorOptions.cs │ ├── App │ │ ├── ApplicationInstanceInfo.cs │ │ └── IApplicationInstanceInfo.cs │ ├── Cache │ │ ├── RedisCacheConfigurationExtensions.cs │ │ ├── RedisCacheConfigurer.cs │ │ ├── RedisCacheConnectorOptions.cs │ │ ├── RedisHealthContributor.cs │ │ ├── RedisServiceConnectorFactory.cs │ │ └── RedisTypeLocator.cs │ ├── CircuitBreaker │ │ ├── HystrixConnectionFactory.cs │ │ ├── HystrixProviderConfigurer.cs │ │ ├── HystrixProviderConnectorFactory.cs │ │ └── HystrixProviderConnectorOptions.cs │ ├── CloudFoundryServiceInfoCreator.cs │ ├── ConnectorException.cs │ ├── ConnectorHelpers.cs │ ├── ConnectorIOptions.cs │ ├── DocumentDB │ │ └── MongoDb │ │ │ ├── MongoDbConnectorFactory.cs │ │ │ ├── MongoDbConnectorOptions.cs │ │ │ ├── MongoDbHealthContributor.cs │ │ │ ├── MongoDbProviderConfigurer.cs │ │ │ └── MongoDbTypeLocator.cs │ ├── IConfigurationExtensions.cs │ ├── OAuth │ │ ├── OAuthConfigurer.cs │ │ ├── OAuthConnectorDefaults.cs │ │ ├── OAuthConnectorFactory.cs │ │ ├── OAuthConnectorOptions.cs │ │ └── OAuthServiceOptions.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Queue │ │ ├── RabbitMQHealthContributor.cs │ │ ├── RabbitMQProviderConfigurer.cs │ │ ├── RabbitMQProviderConnectorFactory.cs │ │ ├── RabbitMQProviderConnectorOptions.cs │ │ └── RabbitMQTypeLocator.cs │ ├── README.md │ ├── Relational │ │ ├── MySql │ │ │ ├── EF6 │ │ │ │ └── MySqlDbContextConnectorFactory.cs │ │ │ ├── MySqlProviderConfigurer.cs │ │ │ ├── MySqlProviderConnectorFactory.cs │ │ │ ├── MySqlProviderConnectorOptions.cs │ │ │ └── MySqlTypeLocator.cs │ │ ├── PostgreSQL │ │ │ ├── PostgreSqlTypeLocator.cs │ │ │ ├── PostgresProviderConfigurer.cs │ │ │ ├── PostgresProviderConnectorFactory.cs │ │ │ └── PostgresProviderConnectorOptions.cs │ │ ├── RelationalHealthContributor.cs │ │ └── SqlServer │ │ │ ├── EF6 │ │ │ └── SqlServerDbContextConnectorFactory.cs │ │ │ ├── SqlServerProviderConfigurer.cs │ │ │ ├── SqlServerProviderConnectorFactory.cs │ │ │ ├── SqlServerProviderConnectorOptions.cs │ │ │ └── SqlServerTypeLocator.cs │ ├── Services │ │ ├── DB2ServiceInfo.cs │ │ ├── DB2ServiceInfoFactory.cs │ │ ├── EurekaServiceInfo.cs │ │ ├── EurekaServiceInfoFactory.cs │ │ ├── HystrixRabbitMQServiceInfo.cs │ │ ├── HystrixRabbitMQServiceInfoFactory.cs │ │ ├── IServiceInfo.cs │ │ ├── IServiceInfoFactory.cs │ │ ├── MongoDbServiceInfo.cs │ │ ├── MongoDbServiceInfoFactory.cs │ │ ├── MySqlServiceInfo.cs │ │ ├── MySqlServiceInfoFactory.cs │ │ ├── OracleServiceInfo.cs │ │ ├── OracleServiceInfoFactory.cs │ │ ├── PostgresServiceInfo.cs │ │ ├── PostgresServiceInfoFactory.cs │ │ ├── RabbitMQServiceInfo.cs │ │ ├── RabbitMQServiceInfoFactory.cs │ │ ├── RedisServiceInfo.cs │ │ ├── RedisServiceInfoFactory.cs │ │ ├── RelationalServiceInfoFactory.cs │ │ ├── ServiceInfo.cs │ │ ├── ServiceInfoFactory.cs │ │ ├── ServiceInfoFactoryAttribute.cs │ │ ├── SqlServerServiceInfo.cs │ │ ├── SqlServerServiceInfoFactory.cs │ │ ├── SsoServiceInfo.cs │ │ ├── SsoServiceInfoFactory.cs │ │ ├── Tags.cs │ │ ├── UriInfo.cs │ │ └── UriServiceInfo.cs │ └── Steeltoe.CloudFoundry.ConnectorBase.csproj └── Steeltoe.CloudFoundry.ConnectorCore │ ├── HystrixProviderServiceCollectionExtensions.cs │ ├── MongoDbProviderServiceCollectionExtensions.cs │ ├── MySqlProviderServiceCollectionExtensions.cs │ ├── MySqlServiceCollectionExtensions.cs │ ├── OAuthServiceCollectionExtensions.cs │ ├── PostgresProviderServiceCollectionExtensions.cs │ ├── PostgresServiceCollectionExtensions.cs │ ├── RabbitMQProviderServiceCollectionExtensions.cs │ ├── RedisCacheServiceCollectionExtensions.cs │ ├── SqlServerProviderServiceCollectionExtensions.cs │ ├── SqlServerServiceCollectionExtensions.cs │ └── Steeltoe.CloudFoundry.ConnectorCore.csproj ├── stylecop.json ├── targetframework.props ├── test ├── Steeltoe.CloudFoundry.Connector.EF6Autofac.Test │ ├── GoodMySqlDbContext.cs │ ├── GoodSqlServerDbContext.cs │ ├── MySqlDbContextContainerBuilderExtensionsTest.cs │ ├── MySqlTypeLocatorTest.cs │ ├── SqlServerDbContextContainerBuilderExtensionsTest.cs │ ├── Steeltoe.CloudFoundry.Connector.EF6Autofac.Test.csproj │ └── xunit.runner.json ├── Steeltoe.CloudFoundry.Connector.EF6Core.Test │ ├── BadMySqlDbContext.cs │ ├── BadSqlServerDbContext.cs │ ├── Good2MySqlDbContext.cs │ ├── Good2SqlServerDbContext.cs │ ├── GoodMySqlDbContext.cs │ ├── GoodSqlServerDbContext.cs │ ├── MySqlDbContextConnectorFactoryTest.cs │ ├── MySqlDbContextServiceCollectionExtensionsTest.cs │ ├── MySqlTestHelpers.cs │ ├── MySqlTypeLocatorTest.cs │ ├── SqlServerDbContextConnectorFactoryTest.cs │ ├── SqlServerDbContextServiceCollectionExtensionsTest.cs │ ├── SqlServerTestHelpers.cs │ ├── Steeltoe.CloudFoundry.Connector.EF6Core.Test.csproj │ ├── TestHelpers.cs │ └── xunit.runner.json ├── Steeltoe.CloudFoundry.Connector.EFCore.Test │ ├── EntityFrameworkCoreTypeLocatorTest.cs │ ├── GoodDbContext.cs │ ├── MySqlDbContextOptionsExtensionsTest.cs │ ├── MySqlTestHelpers.cs │ ├── MySqlTypeLocatorTest.cs │ ├── PostgresDbContextOptionsExtensionsTest.cs │ ├── PostgresTestHelpers.cs │ ├── SqlServerDbContextOptionsExtensionsTest.cs │ ├── SqlServerTestHelpers.cs │ ├── Steeltoe.CloudFoundry.Connector.EFCore.Test.csproj │ ├── TestHelpers.cs │ └── xunit.runner.json ├── Steeltoe.CloudFoundry.ConnectorAutofac.Test │ ├── HystrixContainerBuilderExtensionsTest.cs │ ├── MongoDbContainerBuilderExtensionsTest.cs │ ├── MySqlContainerBuilderExtensionsTest.cs │ ├── MySqlTypeLocatorTest.cs │ ├── OAuthContainerBuilderExtensionsTest.cs │ ├── PostgreSqlContainerBuilderExtensionsTest.cs │ ├── RabbitMQContainerBuilderExtensionsTest.cs │ ├── RedisContainerBuilderExtensionsTest.cs │ ├── SqlServerContainerBuilderExtensionsTest.cs │ └── Steeltoe.CloudFoundry.ConnectorAutofac.Test.csproj ├── Steeltoe.CloudFoundry.ConnectorBase.Test │ ├── AbstractServiceConfigurationTest.cs │ ├── App │ │ └── ApplicationInstanceInfoTest.cs │ ├── Cache │ │ ├── RedisCacheConfigurerTest.cs │ │ ├── RedisCacheConnectorOptionsTest.cs │ │ ├── RedisCacheTestHelpers.cs │ │ ├── RedisHealthContributorTest.cs │ │ ├── RedisServiceConnectorFactoryTest.cs │ │ └── RedisTypeLocatorTest.cs │ ├── CircuitBreaker │ │ ├── HystrixProviderConfigurationTest.cs │ │ ├── HystrixProviderConfigurerTest.cs │ │ └── HystrixProviderConnectorFactoryTest.cs │ ├── CloudFoundryServiceInfoCreatorTest.cs │ ├── ConnectorExceptionTest.cs │ ├── DocumentDB │ │ └── MongoDb │ │ │ ├── MongoDbConnectorFactoryTest.cs │ │ │ ├── MongoDbConnectorOptionsTest.cs │ │ │ ├── MongoDbHealthContributorTest.cs │ │ │ ├── MongoDbProviderConfigurerTest.cs │ │ │ ├── MongoDbTestHelpers.cs │ │ │ └── MongoDbTypeLocatorTest.cs │ ├── OAuth │ │ ├── OAuthConfigurerTest.cs │ │ ├── OAuthConnectorFactoryTest.cs │ │ └── OAuthConnectorOptionsTest.cs │ ├── Queue │ │ ├── RabbitMQConfigurerTest.cs │ │ ├── RabbitMQHealthContributorTest.cs │ │ ├── RabbitMQProviderConnectorOptionsTest.cs │ │ ├── RabbitMQServiceConnectorFactoryTest.cs │ │ └── RabbitMQTypeLocatorTest.cs │ ├── Relational │ │ ├── MySql │ │ │ ├── MySqlProviderConfigurerTest.cs │ │ │ ├── MySqlProviderConnectorFactoryTest.cs │ │ │ ├── MySqlProviderConnectorOptionsTest.cs │ │ │ ├── MySqlTestHelpers.cs │ │ │ └── MySqlTypeLocatorTest.cs │ │ ├── PostgreSQL │ │ │ ├── PostgresProviderConfigurerTest.cs │ │ │ ├── PostgresProviderConnectorFactoryTest.cs │ │ │ ├── PostgresProviderConnectorOptionsTest.cs │ │ │ └── PostgresTestHelpers.cs │ │ ├── PostgreSql │ │ │ └── PostgreSqlTypeLocatorTest.cs │ │ ├── RelationalHealthContributorTest.cs │ │ └── SqlServer │ │ │ ├── SqlServerProviderConfigurerTest.cs │ │ │ ├── SqlServerProviderConnectorFactoryTest.cs │ │ │ ├── SqlServerProviderConnectorOptionsTest.cs │ │ │ ├── SqlServerTestHelpers.cs │ │ │ └── SqlServerTypeLocatorTest.cs │ ├── Services │ │ ├── DB2ServiceInfoFactoryTest.cs │ │ ├── DB2ServiceInfoTest.cs │ │ ├── EurekaServiceInfoFactoryTest.cs │ │ ├── EurekaServiceInfoTest.cs │ │ ├── HystrixRabbitMQServiceInfoFactoryTest.cs │ │ ├── HystrixRabbitMQServiceInfoTest.cs │ │ ├── MongoDbServiceInfoFactoryTest.cs │ │ ├── MongoDbServiceInfoTest.cs │ │ ├── MySqlServiceInfoFactoryTest.cs │ │ ├── MySqlServiceInfoTest.cs │ │ ├── OracleServiceInfoFactoryTest.cs │ │ ├── OracleServiceInfoTest.cs │ │ ├── PostgresServiceInfoTest.cs │ │ ├── PostgressServiceInfoFactory.cs │ │ ├── RabbitMQServiceInfoFactoryTest.cs │ │ ├── RabbitMQServiceInfoTest.cs │ │ ├── RedisServiceInfoFactoryTest.cs │ │ ├── RedisServiceInfoTest.cs │ │ ├── ServiceInfoFactoryTest.cs │ │ ├── ServiceInfoTest.cs │ │ ├── SqlServerInfoFactoryTest.cs │ │ ├── SqlServerInfoTest.cs │ │ ├── SsoServiceInfoFactoryTest.cs │ │ ├── SsoServiceInfoTest.cs │ │ ├── TagsTest.cs │ │ ├── TestServiceInfo.cs │ │ ├── TestServiceInfoFactory.cs │ │ ├── TestUriServiceInfo.cs │ │ ├── UriInfoTest.cs │ │ └── UriServiceInfoTest.cs │ ├── Steeltoe.CloudFoundry.ConnectorBase.Test.csproj │ ├── TestHelpers.cs │ ├── TestServiceConfiguration.cs │ └── xunit.runner.json └── Steeltoe.CloudFoundry.ConnectorCore.Test │ ├── ConnectorIOptionsTest.cs │ ├── HystrixProviderServiceCollectionExtensionsTest.cs │ ├── MongoDbProviderServiceCollectionExtensionsTest.cs │ ├── MongoDbTestHelpers.cs │ ├── MySqlProviderServiceCollectionExtensionsTest.cs │ ├── MySqlServiceCollectionExtensionsTest.cs │ ├── MySqlTestHelpers.cs │ ├── MySqlTypeLocatorTest.cs │ ├── OAuthServiceCollectionExtensionsTest.cs │ ├── PostgresProviderServiceCollectionExtensionsTest.cs │ ├── PostgresServiceCollectionExtensionsTest.cs │ ├── PostgresTestHelpers.cs │ ├── RabbitMQServiceCollectionExtensionsTest.cs │ ├── RedisCacheConfigurationExtensionsTest.cs │ ├── RedisCacheServiceCollectionExtensionsTest.cs │ ├── RedisCacheTestHelpers.cs │ ├── SqlServerProviderServiceCollectionExtensionsTest.cs │ ├── SqlServerServiceCollectionExtensionsTest.cs │ ├── SqlServerTestHelpers.cs │ ├── Steeltoe.CloudFoundry.ConnectorCore.Test.csproj │ ├── TestHelpers.cs │ └── xunit.runner.json └── versions.props /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | *.cs text=auto diff=csharp 17 | *.vb text=auto 18 | *.resx text=auto 19 | *.c text=auto 20 | *.cpp text=auto 21 | *.cxx text=auto 22 | *.h text=auto 23 | *.hxx text=auto 24 | *.py text=auto 25 | *.rb text=auto 26 | *.java text=auto 27 | *.html text=auto 28 | *.htm text=auto 29 | *.css text=auto 30 | *.scss text=auto 31 | *.sass text=auto 32 | *.less text=auto 33 | *.js text=auto 34 | *.lisp text=auto 35 | *.clj text=auto 36 | *.sql text=auto 37 | *.php text=auto 38 | *.lua text=auto 39 | *.m text=auto 40 | *.asm text=auto 41 | *.erl text=auto 42 | *.fs text=auto 43 | *.fsx text=auto 44 | *.hs text=auto 45 | 46 | *.csproj text=auto 47 | *.vbproj text=auto 48 | *.fsproj text=auto 49 | *.dbproj text=auto 50 | *.sln text=auto eol=crlf 51 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | dist: trusty 3 | env: 4 | TestFrameworkVersion: netcoreapp2.1 5 | STEELTOE_VERSION: 2.2.0 6 | global: 7 | - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 8 | - DOTNET_CLI_TELEMETRY_OPTOUT: 1 9 | mono: none 10 | dotnet: 2.1.403 11 | os: 12 | - linux 13 | - osx 14 | osx_image: xcode8.3 15 | branches: 16 | only: 17 | - master 18 | - dev 19 | - /^update[0-9]{2}x/ 20 | script: 21 | - ./steeltoe-ci/scripts/travis_install.sh 22 | - ./steeltoe-ci/scripts/travis_build.sh 23 | - ./steeltoe-ci/scripts/travis_test.sh 24 | before_install: 25 | - git clone https://github.com/SteeltoeOSS/steeltoe-ci.git -v 26 | - if [ "$TRAVIS_OS_NAME" = "osx" ]; then ulimit -n 1024; fi -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you have not previously done so, please fill out and 2 | submit the [Contributor License Agreement](https://cla.pivotal.io/sign/pivotal). 3 | -------------------------------------------------------------------------------- /config/versions-dev.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(STEELTOE_VERSION) 4 | $(STEELTOE_DASH_VERSION_SUFFIX) 5 | 2.2.0-dev-00133 6 | 2.2.0-dev-00343 7 | 2.0.0 8 | 2.0.0 9 | 2.1.1 10 | 2.1.0 11 | 2.1.0 12 | 4.6.1 13 | 4.4.0 14 | 6.2.0 15 | 2.0.0 16 | 2.1.2 17 | 11.0.2 18 | 2.5.0 19 | 8.0.9-dmr 20 | 0.49.3 21 | 6.10.7 22 | 8.0.14 23 | 4.0.0 24 | 2.1.0 25 | 2.0.1 26 | 5.1.0 27 | 4.5.0 28 | 1.2.6 29 | 1.0.2 30 | 15.7.2 31 | 2.3.1 32 | 2.3.1 33 | 1.0.0-beta2-18618-05 34 | 35 | -------------------------------------------------------------------------------- /config/versions-master.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(STEELTOE_VERSION) 4 | $(STEELTOE_DASH_VERSION_SUFFIX) 5 | 2.2.0-master-00134 6 | 2.2.0-master-00336 7 | 2.0.0 8 | 2.0.0 9 | 2.1.1 10 | 2.1.0 11 | 2.1.0 12 | 4.6.1 13 | 4.4.0 14 | 6.2.0 15 | 2.0.0 16 | 2.1.2 17 | 11.0.2 18 | 2.5.0 19 | 8.0.9-dmr 20 | 0.49.3 21 | 6.10.7 22 | 8.0.14 23 | 4.0.0 24 | 2.1.0 25 | 2.0.1 26 | 5.1.0 27 | 4.5.0 28 | 1.2.6 29 | 1.0.2 30 | 15.7.2 31 | 2.3.1 32 | 2.3.1 33 | 1.0.0-beta2-18618-05 34 | 35 | -------------------------------------------------------------------------------- /config/versions.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(STEELTOE_VERSION) 4 | $(STEELTOE_DASH_VERSION_SUFFIX) 5 | 2.2.0 6 | 2.1.1 7 | 2.0.0 8 | 2.0.0 9 | 2.1.1 10 | 2.1.0 11 | 2.1.0 12 | 4.6.1 13 | 4.4.0 14 | 6.2.0 15 | 2.0.0 16 | 2.1.2 17 | 11.0.2 18 | 2.5.0 19 | 8.0.9-dmr 20 | 0.49.3 21 | 6.10.7 22 | 8.0.14 23 | 4.0.0 24 | 2.1.0 25 | 2.0.1 26 | 5.1.0 27 | 4.5.0 28 | 2.0.0 29 | 1.0.2 30 | 15.7.2 31 | 2.3.1 32 | 2.3.1 33 | 1.0.0-beta2-18618-05 34 | 35 | -------------------------------------------------------------------------------- /localSql.cmd: -------------------------------------------------------------------------------- 1 | docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=steeltoe -d mysql:5.6 2 | docker ps 3 | (find container id) 4 | docker exec -it bash 5 | 6 | mysql -u root -p 7 | mysql> create database steeltoe; 8 | mysql> grant all privileges on steeltoe.* to 'steeltoe'@'%'; 9 | mysql> grant all privileges on steeltoe.* to 'steeltoe'@'%' IDENTIFIED BY 'steeltoe'; 10 | mysql> FLUSH PRIVILEGES 11 | 12 | -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.Connector.EF6Autofac/MySqlDbContextContainerBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Autofac.Builder; 17 | using Microsoft.Extensions.Configuration; 18 | using Steeltoe.CloudFoundry.Connector.MySql; 19 | using Steeltoe.CloudFoundry.Connector.Services; 20 | using System; 21 | 22 | namespace Steeltoe.CloudFoundry.Connector.EF6Autofac 23 | { 24 | public static class MySqlDbContextContainerBuilderExtensions 25 | { 26 | /// 27 | /// Add your MySql-based DbContext to the ContainerBuilder 28 | /// 29 | /// Your DbContext 30 | /// Autofac 31 | /// Your app config 32 | /// Name of service instance 33 | /// 34 | public static IRegistrationBuilder RegisterDbContext(this ContainerBuilder container, IConfiguration config, string serviceName = null) 35 | { 36 | if (container == null) 37 | { 38 | throw new ArgumentNullException(nameof(container)); 39 | } 40 | 41 | if (config == null) 42 | { 43 | throw new ArgumentNullException(nameof(config)); 44 | } 45 | 46 | MySqlServiceInfo info = serviceName == null 47 | ? config.GetSingletonServiceInfo() 48 | : config.GetRequiredServiceInfo(serviceName); 49 | 50 | var mySqlConfig = new MySqlProviderConnectorOptions(config); 51 | var factory = new MySqlProviderConnectorFactory(info, mySqlConfig, typeof(TContext)); 52 | return container.Register(c => factory.Create(null)).As(); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.Connector.EF6Autofac/SqlServerDbContextContainerBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Autofac.Builder; 17 | using Microsoft.Extensions.Configuration; 18 | using Steeltoe.CloudFoundry.Connector.Services; 19 | using Steeltoe.CloudFoundry.Connector.SqlServer; 20 | using System; 21 | 22 | namespace Steeltoe.CloudFoundry.Connector.EF6Autofac 23 | { 24 | public static class SqlServerDbContextContainerBuilderExtensions 25 | { 26 | /// 27 | /// Add your SqlServer-based DbContext to the ContainerBuilder 28 | /// 29 | /// Your DbContext 30 | /// Autofac 31 | /// Your app config 32 | /// Name of service instance 33 | /// 34 | public static IRegistrationBuilder RegisterDbContext(this ContainerBuilder container, IConfiguration config, string serviceName = null) 35 | { 36 | if (container == null) 37 | { 38 | throw new ArgumentNullException(nameof(container)); 39 | } 40 | 41 | if (config == null) 42 | { 43 | throw new ArgumentNullException(nameof(config)); 44 | } 45 | 46 | SqlServerServiceInfo info = serviceName == null 47 | ? config.GetSingletonServiceInfo() 48 | : config.GetRequiredServiceInfo(serviceName); 49 | 50 | var sqlServerConfig = new SqlServerProviderConnectorOptions(config); 51 | var factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, typeof(TContext)); 52 | return container.Register(c => factory.Create(null)).As(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.Connector.EF6Autofac/Steeltoe.CloudFoundry.Connector.EF6Autofac.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | CloudFoundry Connector Extensions for Entity Framework 6 with Autofac 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.CloudFoundry.Connector.EF6Autofac 10 | Steeltoe.CloudFoundry.Connector.EF6Autofac 11 | CloudFoundry;ASPNET;Autofac;EntityFramework 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.CloudFoundry.Connector.EF6Autofac.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | All 30 | 31 | 32 | 33 | 34 | 35 | 36 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 37 | 38 | 39 | 40 | stylecop.json 41 | Always 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.Connector.EF6Core/Steeltoe.CloudFoundry.Connector.EF6Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | CloudFoundry Connector Extensions for Entity Framework 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.CloudFoundry.Connector.EF6Core 10 | Steeltoe.CloudFoundry.Connector.EF6Core 11 | CloudFoundry;ASPNET Core;Connectors;EntityFramework 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | All 27 | 28 | 29 | 30 | 31 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 32 | 33 | 34 | 35 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.CloudFoundry.Connector.EF6Core.xml 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | stylecop.json 48 | Always 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.Connector.EFCore/MigrateDbContextTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.EntityFrameworkCore; 16 | using Microsoft.Extensions.Logging; 17 | using Steeltoe.Common.Tasks; 18 | using System.Linq; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.EFCore 21 | { 22 | public class MigrateDbContextTask : IApplicationTask 23 | where T : DbContext 24 | { 25 | private readonly T _db; 26 | private readonly ILogger _logger; 27 | 28 | public MigrateDbContextTask(T db, ILogger> logger) 29 | { 30 | _db = db; 31 | _logger = logger; 32 | } 33 | 34 | public string Name => "migrate"; 35 | 36 | public void Run() 37 | { 38 | var migrations = _db.Database.GetPendingMigrations().ToList(); 39 | _logger.LogInformation("Starting database migration..."); 40 | _db.Database.Migrate(); 41 | if (migrations.Any()) 42 | { 43 | _logger.LogInformation("The following migrations have been successfully applied:"); 44 | foreach (var migration in migrations) 45 | { 46 | _logger.LogInformation(migration); 47 | } 48 | } 49 | else 50 | { 51 | _logger.LogInformation("Database is already up to date"); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorAutofac/OAuthContainerBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Autofac.Builder; 17 | using Microsoft.Extensions.Configuration; 18 | using Microsoft.Extensions.Options; 19 | using Steeltoe.CloudFoundry.Connector; 20 | using Steeltoe.CloudFoundry.Connector.OAuth; 21 | using Steeltoe.CloudFoundry.Connector.Services; 22 | using System; 23 | 24 | namespace Steeltoe.CloudFoundry.ConnectorAutofac 25 | { 26 | public static class OAuthContainerBuilderExtensions 27 | { 28 | /// 29 | /// Adds SsoServiceInfo (as IOptions of type OAuthServiceOptions) to your Autofac Container 30 | /// 31 | /// Your Autofac Container Builder 32 | /// Application configuration 33 | /// Cloud Foundry service name binding 34 | /// the RegistrationBuilder for (optional) additional configuration 35 | public static IRegistrationBuilder RegisterOAuthServiceOptions(this ContainerBuilder container, IConfiguration config, string serviceName = null) 36 | { 37 | if (container == null) 38 | { 39 | throw new ArgumentNullException(nameof(container)); 40 | } 41 | 42 | if (config == null) 43 | { 44 | throw new ArgumentNullException(nameof(config)); 45 | } 46 | 47 | SsoServiceInfo info = serviceName == null 48 | ? config.GetSingletonServiceInfo() 49 | : config.GetRequiredServiceInfo(serviceName); 50 | 51 | var oauthConfig = new OAuthConnectorOptions(config); 52 | var factory = new OAuthConnectorFactory(info, oauthConfig); 53 | 54 | return container.Register(c => factory.Create(null)).As>(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorAutofac/Steeltoe.CloudFoundry.ConnectorAutofac.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CloudFoundry Connector Extensions for Autofac 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.CloudFoundry.ConnectorAutofac 10 | Steeltoe.CloudFoundry.ConnectorAutofac 11 | CloudFoundry;ASPNET;Autofac 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.CloudFoundry.ConnectorAutofac.xml 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | All 30 | 31 | 32 | 33 | 34 | 35 | 36 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 37 | 38 | 39 | 40 | stylecop.json 41 | Always 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/App/IApplicationInstanceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.App 16 | { 17 | public interface IApplicationInstanceInfo 18 | { 19 | string InstanceId { get; } 20 | 21 | string ApplicationId { get; } 22 | 23 | string ApplicationName { get; } 24 | 25 | string[] ApplicationUris { get; } 26 | 27 | string ApplicationVersion { get; } 28 | 29 | int InstanceIndex { get; } 30 | 31 | int Port { get; } 32 | 33 | string SpaceId { get; } 34 | 35 | string SpaceName { get; } 36 | 37 | string[] Uris { get; } 38 | 39 | string Version { get; } 40 | 41 | int DiskLimit { get; } 42 | 43 | int MemoryLimit { get; } 44 | 45 | int FileDescriptorLimit { get; } 46 | 47 | string InstanceIP { get; } 48 | 49 | string InternalIP { get; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Cache/RedisCacheConfigurer.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System.Net; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Redis 19 | { 20 | public class RedisCacheConfigurer 21 | { 22 | /// 23 | /// Create a configuration object to be used to connect to Redis 24 | /// 25 | /// Redis Service Info 26 | /// Configuration parameters 27 | /// A dynamically typed object for use connecting to Redis 28 | public RedisCacheConnectorOptions Configure(RedisServiceInfo si, RedisCacheConnectorOptions configuration) 29 | { 30 | // apply service info to exising configuration 31 | UpdateOptions(si, configuration); 32 | return configuration; 33 | } 34 | 35 | internal void UpdateOptions(RedisServiceInfo si, RedisCacheConnectorOptions configuration) 36 | { 37 | if (si == null) 38 | { 39 | return; 40 | } 41 | 42 | if (!string.IsNullOrEmpty(si.Host)) 43 | { 44 | configuration.Host = si.Host; 45 | configuration.Port = si.Port; 46 | configuration.EndPoints = null; 47 | } 48 | 49 | if (!string.IsNullOrEmpty(si.Password)) 50 | { 51 | if (configuration.UrlEncodedCredentials) 52 | { 53 | configuration.Password = WebUtility.UrlDecode(si.Password); 54 | } 55 | else 56 | { 57 | configuration.Password = si.Password; 58 | } 59 | } 60 | 61 | if (si.Scheme == RedisServiceInfo.REDIS_SECURE_SCHEME) 62 | { 63 | configuration.Ssl = true; 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/CircuitBreaker/HystrixConnectionFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Hystrix 18 | { 19 | public class HystrixConnectionFactory 20 | { 21 | public HystrixConnectionFactory(object realFactory) 22 | { 23 | ConnectionFactory = realFactory ?? throw new ArgumentNullException(nameof(realFactory)); 24 | } 25 | 26 | public object ConnectionFactory { get; private set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/CircuitBreaker/HystrixProviderConfigurer.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Hystrix 18 | { 19 | public class HystrixProviderConfigurer 20 | { 21 | internal string Configure(HystrixRabbitMQServiceInfo si, HystrixProviderConnectorOptions configuration) 22 | { 23 | UpdateConfiguration(si, configuration); 24 | return configuration.ToString(); 25 | } 26 | 27 | internal void UpdateConfiguration(HystrixRabbitMQServiceInfo si, HystrixProviderConnectorOptions configuration) 28 | { 29 | if (si == null) 30 | { 31 | return; 32 | } 33 | 34 | if (!string.IsNullOrEmpty(si.Uri)) 35 | { 36 | if (si.Scheme.Equals(HystrixProviderConnectorOptions.Default_SSLScheme, System.StringComparison.OrdinalIgnoreCase)) 37 | { 38 | configuration.SslEnabled = true; 39 | configuration.SslPort = si.Port; 40 | } 41 | else 42 | { 43 | configuration.Port = si.Port; 44 | } 45 | 46 | configuration.Username = si.UserName; 47 | configuration.Password = si.Password; 48 | configuration.Server = si.Host; 49 | configuration.VirtualHost = si.Path; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/ConnectorException.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector 18 | { 19 | public class ConnectorException : Exception 20 | { 21 | public ConnectorException(string message) 22 | : base(message) 23 | { 24 | } 25 | 26 | public ConnectorException(string message, Exception nested) 27 | : base(message, nested) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/ConnectorIOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Options; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector 18 | { 19 | public class ConnectorIOptions : IOptions 20 | where T : class, new() 21 | { 22 | public ConnectorIOptions(T value) 23 | { 24 | Value = value; 25 | } 26 | 27 | public T Value { get; internal protected set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/DocumentDB/MongoDb/MongoDbConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MongoDb 19 | { 20 | public class MongoDbConnectorFactory 21 | { 22 | private readonly MongoDbServiceInfo _info; 23 | private readonly MongoDbConnectorOptions _config; 24 | private MongoDbProviderConfigurer _configurer = new MongoDbProviderConfigurer(); 25 | 26 | public MongoDbConnectorFactory() 27 | { 28 | } 29 | 30 | public MongoDbConnectorFactory(MongoDbServiceInfo sinfo, MongoDbConnectorOptions config, Type type) 31 | { 32 | _info = sinfo; 33 | _config = config ?? throw new ArgumentNullException(nameof(config)); 34 | ConnectorType = type; 35 | } 36 | 37 | protected Type ConnectorType { get; set; } 38 | 39 | public virtual object Create(IServiceProvider provider) 40 | { 41 | var connectionString = CreateConnectionString(); 42 | object result = null; 43 | if (connectionString != null) 44 | { 45 | result = CreateConnection(connectionString); 46 | } 47 | 48 | if (result == null) 49 | { 50 | throw new ConnectorException(string.Format("Unable to create instance of '{0}'", ConnectorType)); 51 | } 52 | 53 | return result; 54 | } 55 | 56 | public virtual string CreateConnectionString() 57 | { 58 | return _configurer.Configure(_info, _config); 59 | } 60 | 61 | public virtual object CreateConnection(string connectionString) 62 | { 63 | return ConnectorHelpers.CreateInstance(ConnectorType, new object[] { connectionString }); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/DocumentDB/MongoDb/MongoDbProviderConfigurer.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System.Net; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MongoDb 19 | { 20 | public class MongoDbProviderConfigurer 21 | { 22 | public string Configure(MongoDbServiceInfo si, MongoDbConnectorOptions configuration) 23 | { 24 | UpdateConfiguration(si, configuration); 25 | return configuration.ToString(); 26 | } 27 | 28 | public void UpdateConfiguration(MongoDbServiceInfo si, MongoDbConnectorOptions configuration) 29 | { 30 | if (si == null) 31 | { 32 | return; 33 | } 34 | 35 | if (!string.IsNullOrEmpty(si.Uri)) 36 | { 37 | configuration.Uri = si.Uri; 38 | 39 | // the rest of this is unlikely to really be needed when a uri is available 40 | // but the properties are here, so let's go ahead and set them just in case 41 | configuration.Port = si.Port; 42 | if (configuration.UrlEncodedCredentials) 43 | { 44 | configuration.Username = WebUtility.UrlDecode(si.UserName); 45 | configuration.Password = WebUtility.UrlDecode(si.Password); 46 | } 47 | else 48 | { 49 | configuration.Username = si.UserName; 50 | configuration.Password = si.Password; 51 | } 52 | 53 | configuration.Server = si.Host; 54 | configuration.Database = si.Path; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/OAuth/OAuthConnectorDefaults.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.OAuth 16 | { 17 | public class OAuthConnectorDefaults 18 | { 19 | public const string Default_AuthorizationUri = "/oauth/authorize"; 20 | public const string Default_AccessTokenUri = "/oauth/token"; 21 | public const string Default_UserInfoUri = "/userinfo"; 22 | public const string Default_CheckTokenUri = "/check_token"; 23 | public const string Default_JwtTokenKey = "/token_keys"; 24 | public const string Default_OAuthServiceUrl = "Default_OAuthServiceUrl"; 25 | public const string Default_ClientId = "Default_ClientId"; 26 | public const string Default_ClientSecret = "Default_ClientSecret"; 27 | public const bool Default_ValidateCertificates = true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/OAuth/OAuthConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Options; 16 | using Steeltoe.CloudFoundry.Connector.Services; 17 | using System; 18 | 19 | namespace Steeltoe.CloudFoundry.Connector.OAuth 20 | { 21 | public class OAuthConnectorFactory 22 | { 23 | private SsoServiceInfo _info; 24 | private OAuthConnectorOptions _config; 25 | private OAuthConfigurer _configurer = new OAuthConfigurer(); 26 | 27 | public OAuthConnectorFactory(SsoServiceInfo sinfo, OAuthConnectorOptions config) 28 | { 29 | _info = sinfo; 30 | _config = config; 31 | } 32 | 33 | public IOptions Create(IServiceProvider provider) 34 | { 35 | var opts = _configurer.Configure(_info, _config); 36 | return opts; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/OAuth/OAuthServiceOptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Collections.Generic; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.OAuth 18 | { 19 | public class OAuthServiceOptions 20 | { 21 | public string ClientId { get; set; } 22 | 23 | public string ClientSecret { get; set; } 24 | 25 | public string UserAuthorizationUrl { get; set; } 26 | 27 | public string AccessTokenUrl { get; set; } 28 | 29 | public string UserInfoUrl { get; set; } 30 | 31 | public string TokenInfoUrl { get; set; } 32 | 33 | public string JwtKeyUrl { get; set; } 34 | 35 | public ICollection Scope { get; set; } = new HashSet(); 36 | 37 | public bool ValidateCertificates { get; set; } = true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: InternalsVisibleTo("Steeltoe.CloudFoundry.ConnectorBase.Test")] 18 | [assembly: InternalsVisibleTo("Steeltoe.CloudFoundry.Connector.EF6Core.Test")] 19 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Queue/RabbitMQProviderConfigurer.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System.Net; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.RabbitMQ 19 | { 20 | public class RabbitMQProviderConfigurer 21 | { 22 | internal string Configure(RabbitMQServiceInfo si, RabbitMQProviderConnectorOptions configuration) 23 | { 24 | UpdateConfiguration(si, configuration); 25 | return configuration.ToString(); 26 | } 27 | 28 | internal void UpdateConfiguration(RabbitMQServiceInfo si, RabbitMQProviderConnectorOptions configuration) 29 | { 30 | if (si == null) 31 | { 32 | return; 33 | } 34 | 35 | if (!string.IsNullOrEmpty(si.Uri)) 36 | { 37 | if (si.Scheme.Equals(RabbitMQProviderConnectorOptions.Default_SSLScheme, System.StringComparison.OrdinalIgnoreCase)) 38 | { 39 | configuration.SslEnabled = true; 40 | configuration.SslPort = si.Port; 41 | } 42 | else 43 | { 44 | configuration.Port = si.Port; 45 | } 46 | 47 | if (configuration.UrlEncodedCredentials) 48 | { 49 | configuration.Username = WebUtility.UrlDecode(si.UserName); 50 | configuration.Password = WebUtility.UrlDecode(si.Password); 51 | } 52 | else 53 | { 54 | configuration.Username = si.UserName; 55 | configuration.Password = si.Password; 56 | } 57 | 58 | configuration.Server = si.Host; 59 | configuration.VirtualHost = si.Path; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/README.md: -------------------------------------------------------------------------------- 1 | # CloudFoundry .NET Connector 2 | 3 | This project contains base types used in creating Steeltoe Connectors for CloudFoundry. Steeltoe Connectors simplify connecting to services bound to an application on CloudFoundry. 4 | 5 | ## Connector Package Name and Feeds 6 | 7 | `Steeltoe.CloudFoundry.Connector` 8 | 9 | [Development feed (Less Stable)](https://www.myget.org/gallery/steeltoedev) - https://www.myget.org/gallery/steeltoedev 10 | 11 | [Master feed (Stable)](https://www.myget.org/gallery/steeltoemaster) - https://www.myget.org/gallery/steeltoemaster 12 | 13 | [Release or Release Candidate feed](https://www.nuget.org/) - https://www.nuget.org/ 14 | 15 | ## Usage 16 | 17 | You typically will not use the types in this package directly in an application. Normally, you would use these types when you are building a new Connector for CloudFoundry. 18 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/MySql/EF6/MySqlDbContextConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MySql.EF6 19 | { 20 | public class MySqlDbContextConnectorFactory : MySqlProviderConnectorFactory 21 | { 22 | public MySqlDbContextConnectorFactory(MySqlServiceInfo info, MySqlProviderConnectorOptions config, Type dbContextType) 23 | : base(info, config, dbContextType) 24 | { 25 | if (dbContextType == null) 26 | { 27 | throw new ArgumentNullException(nameof(dbContextType)); 28 | } 29 | } 30 | 31 | internal MySqlDbContextConnectorFactory() 32 | { 33 | } 34 | 35 | public override object Create(IServiceProvider arg) 36 | { 37 | var connectionString = CreateConnectionString(); 38 | object result = null; 39 | if (connectionString != null) 40 | { 41 | result = ConnectorHelpers.CreateInstance(ConnectorType, new object[] { connectionString }); 42 | } 43 | 44 | if (result == null) 45 | { 46 | throw new ConnectorException(string.Format("Unable to create instance of '{0}', are you missing 'public {0}(string connectionString)' constructor", ConnectorType)); 47 | } 48 | 49 | return result; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/MySql/MySqlProviderConfigurer.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System.Net; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MySql 19 | { 20 | public class MySqlProviderConfigurer 21 | { 22 | public string Configure(MySqlServiceInfo si, MySqlProviderConnectorOptions configuration) 23 | { 24 | UpdateConfiguration(si, configuration); 25 | return configuration.ToString(); 26 | } 27 | 28 | public void UpdateConfiguration(MySqlServiceInfo si, MySqlProviderConnectorOptions configuration) 29 | { 30 | if (si == null) 31 | { 32 | return; 33 | } 34 | 35 | if (!string.IsNullOrEmpty(si.Uri)) 36 | { 37 | configuration.Port = si.Port; 38 | if (configuration.UrlEncodedCredentials) 39 | { 40 | configuration.Username = WebUtility.UrlDecode(si.UserName); 41 | configuration.Password = WebUtility.UrlDecode(si.Password); 42 | } 43 | else 44 | { 45 | configuration.Username = si.UserName; 46 | configuration.Password = si.Password; 47 | } 48 | 49 | configuration.Server = si.Host; 50 | configuration.Database = si.Path; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/MySql/MySqlProviderConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MySql 19 | { 20 | public class MySqlProviderConnectorFactory 21 | { 22 | private MySqlServiceInfo _info; 23 | private MySqlProviderConnectorOptions _config; 24 | private MySqlProviderConfigurer _configurer = new MySqlProviderConfigurer(); 25 | 26 | public MySqlProviderConnectorFactory() 27 | { 28 | } 29 | 30 | public MySqlProviderConnectorFactory(MySqlServiceInfo sinfo, MySqlProviderConnectorOptions config, Type type) 31 | { 32 | _info = sinfo; 33 | _config = config ?? throw new ArgumentNullException(nameof(config)); 34 | ConnectorType = type; 35 | } 36 | 37 | protected Type ConnectorType { get; set; } 38 | 39 | public virtual object Create(IServiceProvider provider) 40 | { 41 | var connectionString = CreateConnectionString(); 42 | object result = null; 43 | if (connectionString != null) 44 | { 45 | result = CreateConnection(connectionString); 46 | } 47 | 48 | if (result == null) 49 | { 50 | throw new ConnectorException(string.Format("Unable to create instance of '{0}'", ConnectorType)); 51 | } 52 | 53 | return result; 54 | } 55 | 56 | public virtual string CreateConnectionString() 57 | { 58 | return _configurer.Configure(_info, _config); 59 | } 60 | 61 | public virtual object CreateConnection(string connectionString) 62 | { 63 | return ConnectorHelpers.CreateInstance(ConnectorType, new object[] { connectionString }); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/PostgreSQL/PostgresProviderConfigurer.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System.Net; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.PostgreSql 19 | { 20 | public class PostgresProviderConfigurer 21 | { 22 | internal string Configure(PostgresServiceInfo si, PostgresProviderConnectorOptions configuration) 23 | { 24 | UpdateConfiguration(si, configuration); 25 | return configuration.ToString(); 26 | } 27 | 28 | internal void UpdateConfiguration(PostgresServiceInfo si, PostgresProviderConnectorOptions configuration) 29 | { 30 | if (si == null) 31 | { 32 | return; 33 | } 34 | 35 | if (!string.IsNullOrEmpty(si.Uri)) 36 | { 37 | configuration.Port = si.Port; 38 | if (configuration.UrlEncodedCredentials) 39 | { 40 | configuration.Username = WebUtility.UrlDecode(si.UserName); 41 | configuration.Password = WebUtility.UrlDecode(si.Password); 42 | } 43 | else 44 | { 45 | configuration.Username = si.UserName; 46 | configuration.Password = si.Password; 47 | } 48 | 49 | configuration.Host = si.Host; 50 | configuration.Database = si.Path; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/PostgreSQL/PostgresProviderConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.PostgreSql 19 | { 20 | public class PostgresProviderConnectorFactory 21 | { 22 | private PostgresServiceInfo _info; 23 | private PostgresProviderConnectorOptions _config; 24 | private PostgresProviderConfigurer _configurer = new PostgresProviderConfigurer(); 25 | private Type _type; 26 | 27 | public PostgresProviderConnectorFactory(PostgresServiceInfo sinfo, PostgresProviderConnectorOptions config, Type type) 28 | { 29 | _info = sinfo; 30 | _config = config ?? throw new ArgumentNullException(nameof(config)); 31 | _type = type; 32 | } 33 | 34 | internal PostgresProviderConnectorFactory() 35 | { 36 | } 37 | 38 | public virtual object Create(IServiceProvider provider) 39 | { 40 | var connectionString = CreateConnectionString(); 41 | object result = null; 42 | if (connectionString != null) 43 | { 44 | result = CreateConnection(connectionString); 45 | } 46 | 47 | if (result == null) 48 | { 49 | throw new ConnectorException(string.Format("Unable to create instance of '{0}'", _type)); 50 | } 51 | 52 | return result; 53 | } 54 | 55 | public virtual string CreateConnectionString() 56 | { 57 | return _configurer.Configure(_info, _config); 58 | } 59 | 60 | public virtual object CreateConnection(string connectionString) 61 | { 62 | return ConnectorHelpers.CreateInstance(_type, new object[] { connectionString }); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/SqlServer/EF6/SqlServerDbContextConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.SqlServer.EF6 19 | { 20 | public class SqlServerDbContextConnectorFactory : SqlServerProviderConnectorFactory 21 | { 22 | public SqlServerDbContextConnectorFactory(SqlServerServiceInfo info, SqlServerProviderConnectorOptions config, Type dbContextType) 23 | : base(info, config, dbContextType) 24 | { 25 | if (dbContextType == null) 26 | { 27 | throw new ArgumentNullException(nameof(dbContextType)); 28 | } 29 | } 30 | 31 | internal SqlServerDbContextConnectorFactory() 32 | { 33 | } 34 | 35 | public override object Create(IServiceProvider arg) 36 | { 37 | var connectionString = CreateConnectionString(); 38 | object result = null; 39 | if (connectionString != null) 40 | { 41 | result = ConnectorHelpers.CreateInstance(ConnectorType, new object[] { connectionString }); 42 | } 43 | 44 | if (result == null) 45 | { 46 | throw new ConnectorException(string.Format("Unable to create instance of '{0}', are you missing 'public {0}(string connectionString)' constructor", ConnectorType)); 47 | } 48 | 49 | return result; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Relational/SqlServer/SqlServerProviderConnectorFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.SqlServer 19 | { 20 | public class SqlServerProviderConnectorFactory 21 | { 22 | private SqlServerServiceInfo _info; 23 | private SqlServerProviderConnectorOptions _config; 24 | private SqlServerProviderConfigurer _configurer = new SqlServerProviderConfigurer(); 25 | 26 | public SqlServerProviderConnectorFactory() 27 | { 28 | } 29 | 30 | public SqlServerProviderConnectorFactory(SqlServerServiceInfo sinfo, SqlServerProviderConnectorOptions config, Type type) 31 | { 32 | _config = config ?? throw new ArgumentNullException(nameof(config)); 33 | _info = sinfo; 34 | ConnectorType = type; 35 | } 36 | 37 | protected Type ConnectorType { get; set; } 38 | 39 | public virtual object Create(IServiceProvider provider) 40 | { 41 | var connectionString = CreateConnectionString(); 42 | object result = null; 43 | if (connectionString != null) 44 | { 45 | result = CreateConnection(connectionString); 46 | } 47 | 48 | if (result == null) 49 | { 50 | throw new ConnectorException(string.Format("Unable to create instance of '{0}'", ConnectorType)); 51 | } 52 | 53 | return result; 54 | } 55 | 56 | public virtual string CreateConnectionString() 57 | { 58 | return _configurer.Configure(_info, _config); 59 | } 60 | 61 | public virtual object CreateConnection(string connectionString) 62 | { 63 | return ConnectorHelpers.CreateInstance(ConnectorType, new object[] { connectionString }); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/DB2ServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class DB2ServiceInfo : UriServiceInfo 20 | { 21 | public const string DB2_SCHEME = "db2"; 22 | 23 | public DB2ServiceInfo(string id, string url) 24 | : base(id, url) 25 | { 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/DB2ServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class DB2ServiceInfoFactory : RelationalServiceInfoFactory 18 | { 19 | private static Tags _db2tags = new Tags(new string[] { "sqldb", "dashDB", "db2" }); 20 | 21 | public DB2ServiceInfoFactory() 22 | : base(_db2tags, DB2ServiceInfo.DB2_SCHEME) 23 | { 24 | } 25 | 26 | public override IServiceInfo Create(string id, string url) 27 | { 28 | return new DB2ServiceInfo(id, url); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/EurekaServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class EurekaServiceInfo : UriServiceInfo 18 | { 19 | public EurekaServiceInfo(string id, string uri, string clientId, string clientSecret, string tokenUri) 20 | : base(id, uri) 21 | { 22 | ClientId = clientId; 23 | ClientSecret = clientSecret; 24 | TokenUri = tokenUri; 25 | } 26 | 27 | public string ClientId { get; internal set; } 28 | 29 | public string ClientSecret { get; internal set; } 30 | 31 | public string TokenUri { get; internal set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/EurekaServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class EurekaServiceInfoFactory : ServiceInfoFactory 20 | { 21 | public EurekaServiceInfoFactory() 22 | : base(new Tags("eureka"), new string[0]) 23 | { 24 | } 25 | 26 | public override IServiceInfo Create(Service binding) 27 | { 28 | string uri = GetUriFromCredentials(binding.Credentials); 29 | string clientId = GetClientIdFromCredentials(binding.Credentials); 30 | string clientSecret = GetClientSecretFromCredentials(binding.Credentials); 31 | string accessTokenUri = GetAccessTokenUriFromCredentials(binding.Credentials); 32 | 33 | return new EurekaServiceInfo(binding.Name, uri, clientId, clientSecret, accessTokenUri); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/IServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.App; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public interface IServiceInfo 20 | { 21 | string Id { get; } 22 | 23 | IApplicationInstanceInfo ApplicationInfo { get; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/IServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | internal interface IServiceInfoFactory 20 | { 21 | bool Accept(Service binding); 22 | 23 | IServiceInfo Create(Service binding); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/MongoDbServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class MongoDbServiceInfo : UriServiceInfo 18 | { 19 | public const string MONGODB_SCHEME = "mongodb"; 20 | 21 | public MongoDbServiceInfo(string id, string host, int port, string username, string password, string db) 22 | : base(id, MONGODB_SCHEME, host, port, username, password, db) 23 | { 24 | } 25 | 26 | public MongoDbServiceInfo(string id, string uri) 27 | : base(id, uri) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/MongoDbServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class MongoDbServiceInfoFactory : ServiceInfoFactory 20 | { 21 | public MongoDbServiceInfoFactory() 22 | : base(new Tags("mongodb"), MongoDbServiceInfo.MONGODB_SCHEME) 23 | { 24 | } 25 | 26 | public override IServiceInfo Create(Service binding) 27 | { 28 | string uri = GetUriFromCredentials(binding.Credentials); 29 | return new MongoDbServiceInfo(binding.Name, uri); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/MySqlServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class MySqlServiceInfo : UriServiceInfo 18 | { 19 | public const string MYSQL_SCHEME = "mysql"; 20 | 21 | public MySqlServiceInfo(string id, string url) 22 | : base(id, url) 23 | { 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/MySqlServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class MySqlServiceInfoFactory : RelationalServiceInfoFactory 18 | { 19 | public MySqlServiceInfoFactory() 20 | : base(new Tags("mysql"), MySqlServiceInfo.MYSQL_SCHEME) 21 | { 22 | } 23 | 24 | public override IServiceInfo Create(string id, string url) 25 | { 26 | return new MySqlServiceInfo(id, url); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/OracleServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class OracleServiceInfo : UriServiceInfo 18 | { 19 | public const string ORACLE_SCHEME = "oracle"; 20 | 21 | public OracleServiceInfo(string id, string url) 22 | : base(id, url) 23 | { 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/OracleServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class OracleServiceInfoFactory : RelationalServiceInfoFactory 18 | { 19 | public OracleServiceInfoFactory() 20 | : base(new Tags(), OracleServiceInfo.ORACLE_SCHEME) 21 | { 22 | } 23 | 24 | public override IServiceInfo Create(string id, string url) 25 | { 26 | return new OracleServiceInfo(id, url); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/PostgresServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class PostgresServiceInfo : UriServiceInfo 18 | { 19 | public const string POSTGRES_SCHEME = "postgres"; 20 | public const string POSTGRES_JDBC_SCHEME = "postgresql"; 21 | 22 | public PostgresServiceInfo(string id, string url, bool urlEncodedCredentials = false) 23 | : base(id, url, urlEncodedCredentials) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/PostgresServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class PostgresServiceInfoFactory : RelationalServiceInfoFactory 18 | { 19 | private static string[] _postschemes = new string[] { PostgresServiceInfo.POSTGRES_SCHEME, PostgresServiceInfo.POSTGRES_JDBC_SCHEME }; 20 | 21 | public PostgresServiceInfoFactory() 22 | : base(new Tags("postgresql"), _postschemes) 23 | { 24 | } 25 | 26 | public override IServiceInfo Create(string id, string url) 27 | { 28 | return new PostgresServiceInfo(id, url); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/RabbitMQServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Collections.Generic; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class RabbitMQServiceInfo : UriServiceInfo 20 | { 21 | public const string AMQP_SCHEME = "amqp"; 22 | public const string AMQPS_SCHEME = "amqps"; 23 | 24 | public RabbitMQServiceInfo(string id, string host, int port, string username, string password, string virtualHost) 25 | : this(id, host, port, username, password, virtualHost, null) 26 | { 27 | } 28 | 29 | public RabbitMQServiceInfo(string id, string host, int port, string username, string password, string virtualHost, string managementUri) 30 | : base(id, AMQP_SCHEME, host, port, username, password, virtualHost) 31 | { 32 | ManagementUri = managementUri; 33 | } 34 | 35 | public RabbitMQServiceInfo(string id, string uri, string managementUri, List uris, List managementUris) 36 | : this(id, uri, managementUri) 37 | { 38 | Uris = uris; 39 | ManagementUris = managementUris; 40 | } 41 | 42 | public RabbitMQServiceInfo(string id, string uri) 43 | : this(id, uri, null) 44 | { 45 | } 46 | 47 | public RabbitMQServiceInfo(string id, string uri, string managementUri) 48 | : base(id, uri) 49 | { 50 | ManagementUri = managementUri; 51 | } 52 | 53 | public string ManagementUri { get; internal protected set; } 54 | 55 | public List Uris { get; internal protected set; } 56 | 57 | public List ManagementUris { get; internal protected set; } 58 | 59 | public string VirtualHost 60 | { 61 | get 62 | { 63 | return Info.Path; 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/RabbitMQServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | using System.Collections.Generic; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Services 19 | { 20 | public class RabbitMQServiceInfoFactory : ServiceInfoFactory 21 | { 22 | public static readonly Tags RABBIT_SERVICE_TAGS = new Tags("rabbit"); 23 | 24 | private static string[] _scheme = new string[] { RabbitMQServiceInfo.AMQP_SCHEME, RabbitMQServiceInfo.AMQPS_SCHEME }; 25 | 26 | public RabbitMQServiceInfoFactory() 27 | : base(RABBIT_SERVICE_TAGS, _scheme) 28 | { 29 | } 30 | 31 | public override bool Accept(Service binding) 32 | { 33 | bool result = base.Accept(binding); 34 | if (result) 35 | { 36 | result = !HystrixRabbitMQServiceInfoFactory.HYSTRIX_RABBIT_SERVICE_TAGS.ContainsOne(binding.Tags); 37 | } 38 | 39 | return result; 40 | } 41 | 42 | public override IServiceInfo Create(Service binding) 43 | { 44 | string uri = GetUriFromCredentials(binding.Credentials); 45 | string managementUri = GetStringFromCredentials(binding.Credentials, "http_api_uri"); 46 | 47 | if (binding.Credentials.ContainsKey("uris")) 48 | { 49 | List uris = GetListFromCredentials(binding.Credentials, "uris"); 50 | List managementUris = GetListFromCredentials(binding.Credentials, "http_api_uris"); 51 | return new RabbitMQServiceInfo(binding.Name, uri, managementUri, uris, managementUris); 52 | } 53 | 54 | return new RabbitMQServiceInfo(binding.Name, uri, managementUri); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/RedisServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class RedisServiceInfo : UriServiceInfo 20 | { 21 | public const string REDIS_SCHEME = "redis"; 22 | public const string REDIS_SECURE_SCHEME = "rediss"; 23 | 24 | public RedisServiceInfo(string id, string host, int port, string password) 25 | : base(id, REDIS_SCHEME, host, port, null, password, null) 26 | { 27 | } 28 | 29 | public RedisServiceInfo(string id, string uri) 30 | : base(id, uri) 31 | { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/RedisServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class RedisServiceInfoFactory : ServiceInfoFactory 20 | { 21 | public RedisServiceInfoFactory() 22 | : base(new Tags("redis"), new string[] { RedisServiceInfo.REDIS_SCHEME, RedisServiceInfo.REDIS_SECURE_SCHEME }) 23 | { 24 | } 25 | 26 | public override IServiceInfo Create(Service binding) 27 | { 28 | string uri = GetUriFromCredentials(binding.Credentials); 29 | if (string.IsNullOrEmpty(uri)) 30 | { 31 | string host = GetHostFromCredentials(binding.Credentials); 32 | int port = GetPortFromCredentials(binding.Credentials); 33 | string password = GetPasswordFromCredentials(binding.Credentials); 34 | 35 | return new RedisServiceInfo(binding.Name, host, port, password); 36 | } 37 | else 38 | { 39 | return new RedisServiceInfo(binding.Name, uri); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/RelationalServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Services 19 | { 20 | public abstract class RelationalServiceInfoFactory : ServiceInfoFactory 21 | { 22 | public RelationalServiceInfoFactory(Tags tags, string scheme) 23 | : base(tags, scheme) 24 | { 25 | } 26 | 27 | public RelationalServiceInfoFactory(Tags tags, string[] schemes) 28 | : base(tags, schemes) 29 | { 30 | } 31 | 32 | public override IServiceInfo Create(Service binding) 33 | { 34 | string uri = GetUriFromCredentials(binding.Credentials); 35 | if (uri == null) 36 | { 37 | string host = GetHostFromCredentials(binding.Credentials); 38 | int port = GetPortFromCredentials(binding.Credentials); 39 | 40 | string username = GetUsernameFromCredentials(binding.Credentials); 41 | string password = GetPasswordFromCredentials(binding.Credentials); 42 | 43 | string database = GetStringFromCredentials(binding.Credentials, "name"); 44 | 45 | if (host != null) 46 | { 47 | uri = new UriInfo(DefaultUriScheme, host, port, username, password, database).ToString(); 48 | } 49 | } 50 | 51 | return Create(binding.Name, uri); 52 | } 53 | 54 | public abstract IServiceInfo Create(string id, string url); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/ServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.App; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Services 19 | { 20 | public abstract class ServiceInfo : IServiceInfo 21 | { 22 | public ServiceInfo(string id) 23 | : this(id, null) 24 | { 25 | } 26 | 27 | public ServiceInfo(string id, ApplicationInstanceInfo info) 28 | { 29 | if (string.IsNullOrEmpty(id)) 30 | { 31 | throw new ArgumentNullException(nameof(id)); 32 | } 33 | 34 | Id = id; 35 | ApplicationInfo = info; 36 | } 37 | 38 | public string Id { get; internal protected set; } 39 | 40 | public IApplicationInstanceInfo ApplicationInfo { get; internal protected set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/ServiceInfoFactoryAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class ServiceInfoFactoryAttribute : Attribute 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/SqlServerServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class SqlServerServiceInfo : UriServiceInfo 18 | { 19 | public static readonly string[] SQLSERVER_SCHEME = { "sqlserver", "jdbc:sqlserver", "mssql" }; 20 | 21 | public SqlServerServiceInfo(string id, string url) 22 | : base(id, url) 23 | { 24 | } 25 | 26 | public SqlServerServiceInfo(string id, string url, string username, string password) 27 | : base(id, url, username, password) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/SqlServerServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class SqlServerServiceInfoFactory : ServiceInfoFactory 20 | { 21 | public SqlServerServiceInfoFactory() 22 | : base(new Tags("sqlserver"), SqlServerServiceInfo.SQLSERVER_SCHEME) 23 | { 24 | } 25 | 26 | public SqlServerServiceInfoFactory(Tags tags, string scheme) 27 | : base(tags, scheme) 28 | { 29 | } 30 | 31 | public SqlServerServiceInfoFactory(Tags tags, string[] schemes) 32 | : base(tags, schemes) 33 | { 34 | } 35 | 36 | public override IServiceInfo Create(Service binding) 37 | { 38 | string uri = GetUriFromCredentials(binding.Credentials); 39 | string username = GetUsernameFromCredentials(binding.Credentials); 40 | string password = GetPasswordFromCredentials(binding.Credentials); 41 | 42 | if (uri == null) 43 | { 44 | string host = GetHostFromCredentials(binding.Credentials); 45 | int port = GetPortFromCredentials(binding.Credentials); 46 | 47 | string database = GetStringFromCredentials(binding.Credentials, "name"); 48 | 49 | if (host != null) 50 | { 51 | uri = new UriInfo(DefaultUriScheme, host, port, username, password, database).ToString(); 52 | } 53 | } 54 | 55 | return Create(binding.Name, uri, username, password); 56 | } 57 | 58 | public IServiceInfo Create(string id, string url, string username, string password) 59 | { 60 | if (username == null && password == null) 61 | { 62 | return new SqlServerServiceInfo(id, url); 63 | } 64 | else 65 | { 66 | return new SqlServerServiceInfo(id, url, username, password); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/SsoServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public class SsoServiceInfo : ServiceInfo 18 | { 19 | public SsoServiceInfo(string id, string clientId, string clientSecret, string domain) 20 | : base(id) 21 | { 22 | ClientId = clientId; 23 | ClientSecret = clientSecret; 24 | AuthDomain = domain; 25 | } 26 | 27 | public string ClientId { get; internal set; } 28 | 29 | public string ClientSecret { get; internal set; } 30 | 31 | public string AuthDomain { get; internal set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/SsoServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class SsoServiceInfoFactory : ServiceInfoFactory 20 | { 21 | public SsoServiceInfoFactory() 22 | : base(new Tags("p-identity"), "uaa") 23 | { 24 | } 25 | 26 | public override IServiceInfo Create(Service binding) 27 | { 28 | string clientId = GetClientIdFromCredentials(binding.Credentials); 29 | string clientSecret = GetClientSecretFromCredentials(binding.Credentials); 30 | string authDomain = GetStringFromCredentials(binding.Credentials, "auth_domain"); 31 | string uri = GetUriFromCredentials(binding.Credentials); 32 | 33 | if (!string.IsNullOrEmpty(authDomain)) 34 | { 35 | return new SsoServiceInfo(binding.Name, clientId, clientSecret, authDomain); 36 | } 37 | 38 | if (!string.IsNullOrEmpty(uri)) 39 | { 40 | return new SsoServiceInfo(binding.Name, clientId, clientSecret, UpdateUaaScheme(uri)); 41 | } 42 | 43 | return null; 44 | } 45 | 46 | internal string UpdateUaaScheme(string uaaString) 47 | { 48 | if (uaaString.StartsWith("uaa:")) 49 | { 50 | return "https:" + uaaString.Substring(4); 51 | } 52 | 53 | return uaaString; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/Tags.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Linq; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services 18 | { 19 | public class Tags 20 | { 21 | public Tags(string tag) 22 | : this(new string[] { tag }) 23 | { 24 | } 25 | 26 | public Tags(string[] tags) 27 | { 28 | if (tags == null) 29 | { 30 | Values = new string[0]; 31 | } 32 | else 33 | { 34 | Values = tags; 35 | } 36 | } 37 | 38 | internal Tags() 39 | { 40 | } 41 | 42 | public string[] Values { get; internal protected set; } 43 | 44 | public bool ContainsOne(string[] tags) 45 | { 46 | if (tags != null) 47 | { 48 | if (Values != null) 49 | { 50 | foreach (string value in Values) 51 | { 52 | if (tags.Contains(value)) 53 | { 54 | return true; 55 | } 56 | } 57 | } 58 | } 59 | 60 | return false; 61 | } 62 | 63 | public bool Contains(string tag) 64 | { 65 | if (Values == null) 66 | { 67 | return false; 68 | } 69 | 70 | return Values.Contains(tag); 71 | } 72 | 73 | public bool StartsWith(string tag) 74 | { 75 | if (tag != null) 76 | { 77 | if (Values != null) 78 | { 79 | foreach (string t in Values) 80 | { 81 | if (tag.StartsWith(t)) 82 | { 83 | return true; 84 | } 85 | } 86 | } 87 | } 88 | 89 | return false; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Services/UriServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services 16 | { 17 | public abstract class UriServiceInfo : ServiceInfo 18 | { 19 | public UriServiceInfo(string id, string scheme, string host, int port, string username, string password, string path) 20 | : base(id) 21 | { 22 | Info = new UriInfo(scheme, host, port, username, password, path); 23 | } 24 | 25 | public UriServiceInfo(string id, string uriString, string username, string password) 26 | : base(id) 27 | { 28 | Info = new UriInfo(uriString, username, password); 29 | } 30 | 31 | public UriServiceInfo(string id, string uriString, bool urlEncodedCredentials = false) 32 | : base(id) 33 | { 34 | Info = new UriInfo(uriString, urlEncodedCredentials); 35 | } 36 | 37 | public UriInfo Info { get; internal protected set; } 38 | 39 | public string Uri => Info.UriString; 40 | 41 | public string UserName => Info.UserName; 42 | 43 | public string Password => Info.Password; 44 | 45 | public string Host => Info.Host; 46 | 47 | public string[] Hosts => Info.Hosts; 48 | 49 | public int Port => Info.Port; 50 | 51 | public string Path => Info.Path; 52 | 53 | public string Query => Info.Query; 54 | 55 | public string Scheme => Info.Scheme; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Steeltoe.CloudFoundry.ConnectorBase/Steeltoe.CloudFoundry.ConnectorBase.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | CloudFoundry Connectors for .NET, Base package 5 | $(SteeltoeVersion) 6 | $(VersionSuffix) 7 | Pivotal;dtillman 8 | netstandard2.0 9 | Steeltoe.CloudFoundry.ConnectorBase 10 | Steeltoe.CloudFoundry.ConnectorBase 11 | CloudFoundry;Connectors 12 | https://steeltoe.io/images/transparent.png 13 | https://steeltoe.io 14 | https://www.apache.org/licenses/LICENSE-2.0 15 | true 16 | true 17 | snupkg 18 | 19 | 20 | 21 | bin\$(Configuration)\$(TargetFramework)\Steeltoe.CloudFoundry.ConnectorBase.xml 22 | 23 | 24 | 25 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | All 37 | 38 | 39 | 40 | 41 | 42 | stylecop.json 43 | Always 44 | 45 | 46 | -------------------------------------------------------------------------------- /stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "documentationRules": { 5 | "copyrightText": "Copyright {copyrightYear} the original author or authors.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttps://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", 6 | "xmlHeader": false, 7 | "variables": { 8 | "copyrightYear": "2017" 9 | }, 10 | "documentExposedElements": false, 11 | "documentInternalElements": false, 12 | "documentPrivateElements": false 13 | }, 14 | "indentation": { 15 | "useTabs": false, 16 | "indentationSize": 4 17 | }, 18 | "namingRules": { 19 | }, 20 | "orderingRules": { 21 | "usingDirectivesPlacement": "outsideNamespace", 22 | "systemUsingDirectivesFirst": false 23 | }, 24 | "readabilityRules": { 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /targetframework.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(NuGetPackageRoot)microsoft.targetingpack.netframework.v4.6.1/1.0.1/lib/net461/ 4 | https://dotnet.myget.org/F/dotnet-core/api/v3/index.json 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/GoodMySqlDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using MySql.Data.Entity; 16 | using System.Data.Entity; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.EF6Autofac.Test 19 | { 20 | [DbConfigurationType(typeof(MySqlEFConfiguration))] 21 | public class GoodMySqlDbContext : DbContext 22 | { 23 | public GoodMySqlDbContext(string str) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/GoodSqlServerDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Data.Entity; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.EF6Autofac.Test 18 | { 19 | public class GoodSqlServerDbContext : DbContext 20 | { 21 | public GoodSqlServerDbContext(string str) 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/MySqlDbContextContainerBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.EF6Autofac.Test 21 | { 22 | public class MySqlDbContextContainerBuilderExtensionsTest 23 | { 24 | [Fact] 25 | public void RegisterMySqlDbContext_Requires_Builder() 26 | { 27 | // arrange 28 | IConfiguration config = new ConfigurationBuilder().Build(); 29 | 30 | // act & assert 31 | Assert.Throws(() => MySqlDbContextContainerBuilderExtensions.RegisterDbContext(null, config)); 32 | } 33 | 34 | [Fact] 35 | public void RegisterMySqlDbContext_Requires_Config() 36 | { 37 | // arrange 38 | var cb = new ContainerBuilder(); 39 | 40 | // act & assert 41 | Assert.Throws(() => MySqlDbContextContainerBuilderExtensions.RegisterDbContext(cb, null)); 42 | } 43 | 44 | [Fact] 45 | public void RegisterMySqlDbContext_AddsToContainer() 46 | { 47 | // arrange 48 | var container = new ContainerBuilder(); 49 | IConfiguration config = new ConfigurationBuilder().Build(); 50 | 51 | // act 52 | var regBuilder = MySqlDbContextContainerBuilderExtensions.RegisterDbContext(container, config); 53 | var services = container.Build(); 54 | var dbConn = services.Resolve(); 55 | 56 | // assert 57 | Assert.NotNull(dbConn); 58 | Assert.IsType(dbConn); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/MySqlTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.MySql.Test 18 | { 19 | public class MySqlTypeLocatorTest 20 | { 21 | /// 22 | /// These tests can be found in Base, EF6 Autofac, EF6 Core and EF Core, for testing different nuget packages. 23 | /// This version should be testing the v6 line of the Oracle driver, brought in by the v6 line of MySql.Data.Entity 24 | /// Don't remove it unless you've got a better idea for making sure we work with multiple assemblies 25 | /// with conflicting names/types 26 | /// 27 | [Fact] 28 | public void Property_Can_Locate_ConnectionType() 29 | { 30 | // arrange -- handled by including a compatible MySql NuGet package 31 | 32 | // act 33 | var type = MySqlTypeLocator.MySqlConnection; 34 | 35 | // assert 36 | Assert.NotNull(type); 37 | } 38 | 39 | [Fact] 40 | public void Driver_Found_In_MySqlData_Assembly() 41 | { 42 | // arrange ~ narrow the assembly list to one specific nuget package 43 | var assemblies = MySqlTypeLocator.Assemblies; 44 | MySqlTypeLocator.Assemblies = new string[] { "MySql.Data" }; 45 | 46 | // act 47 | var type = MySqlTypeLocator.MySqlConnection; 48 | 49 | // assert 50 | Assert.NotNull(type); 51 | MySqlTypeLocator.Assemblies = assemblies; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/SqlServerDbContextContainerBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.EF6Autofac.Test 21 | { 22 | public class SqlServerDbContextContainerBuilderExtensionsTest 23 | { 24 | [Fact] 25 | public void RegisterSqlServerDbContext_Requires_Builder() 26 | { 27 | // arrange 28 | IConfiguration config = new ConfigurationBuilder().Build(); 29 | 30 | // act & assert 31 | Assert.Throws(() => SqlServerDbContextContainerBuilderExtensions.RegisterDbContext(null, config)); 32 | } 33 | 34 | [Fact] 35 | public void RegisterMySqlDbContext_Requires_Config() 36 | { 37 | // arrange 38 | var cb = new ContainerBuilder(); 39 | 40 | // act & assert 41 | Assert.Throws(() => SqlServerDbContextContainerBuilderExtensions.RegisterDbContext(cb, null)); 42 | } 43 | 44 | [Fact] 45 | public void RegisterMySqlDbContext_AddsToContainer() 46 | { 47 | // arrange 48 | var container = new ContainerBuilder(); 49 | IConfiguration config = new ConfigurationBuilder().Build(); 50 | 51 | // act 52 | var regBuilder = SqlServerDbContextContainerBuilderExtensions.RegisterDbContext(container, config); 53 | var services = container.Build(); 54 | var dbConn = services.Resolve(); 55 | 56 | // assert 57 | Assert.NotNull(dbConn); 58 | Assert.IsType(dbConn); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | All 34 | 35 | 36 | 37 | 38 | 39 | stylecop.json 40 | Always 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Autofac.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/BadMySqlDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using MySql.Data.EntityFramework; 16 | using System.Data.Entity; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MySql.EF6.Test 19 | { 20 | [DbConfigurationType(typeof(MySqlEFConfiguration))] 21 | public class BadMySqlDbContext : DbContext 22 | { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/BadSqlServerDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Data.Entity; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.SqlServer.EF6.Test 18 | { 19 | public class BadSqlServerDbContext : DbContext 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/Good2MySqlDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using MySql.Data.EntityFramework; 16 | using System.Data.Entity; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MySql.EF6.Test 19 | { 20 | [DbConfigurationType(typeof(MySqlEFConfiguration))] 21 | public class Good2MySqlDbContext : DbContext 22 | { 23 | public Good2MySqlDbContext(string str) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/Good2SqlServerDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Data.Entity; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.SqlServer.EF6.Test 18 | { 19 | public class Good2SqlServerDbContext : DbContext 20 | { 21 | public Good2SqlServerDbContext(string str) 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/GoodMySqlDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using MySql.Data.EntityFramework; 16 | using System.Data.Entity; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.MySql.EF6.Test 19 | { 20 | [DbConfigurationType(typeof(MySqlEFConfiguration))] 21 | public class GoodMySqlDbContext : DbContext 22 | { 23 | public GoodMySqlDbContext(string str) 24 | { 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/GoodSqlServerDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.Data.Entity; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.SqlServer.EF6.Test 18 | { 19 | public class GoodSqlServerDbContext : DbContext 20 | { 21 | public GoodSqlServerDbContext(string str) 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/MySqlTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.MySql.Test 18 | { 19 | /// 20 | /// These tests can be found in Base, EF6 Autofac, EF6 Core and EF Core, for testing different nuget packages. 21 | /// This version should be testing the v8+ line of the Oracle driver, brought in by v8+ of MySql.Data.EntityFramework 22 | /// Don't remove it unless you've got a better idea for making sure we work with multiple assemblies 23 | /// with conflicting names/types 24 | /// 25 | public class MySqlTypeLocatorTest 26 | { 27 | [Fact] 28 | public void Property_Can_Locate_ConnectionType() 29 | { 30 | // arrange -- handled by including a compatible MySql NuGet package 31 | 32 | // act 33 | var type = MySqlTypeLocator.MySqlConnection; 34 | 35 | // assert 36 | Assert.NotNull(type); 37 | } 38 | 39 | [Fact] 40 | public void Driver_Found_In_MySqlData_Assembly() 41 | { 42 | // arrange ~ narrow the assembly list to one specific nuget package 43 | var assemblies = MySqlTypeLocator.Assemblies; 44 | MySqlTypeLocator.Assemblies = new string[] { "MySql.Data" }; 45 | 46 | // act 47 | var type = MySqlTypeLocator.MySqlConnection; 48 | 49 | // assert 50 | Assert.NotNull(type); 51 | MySqlTypeLocator.Assemblies = assemblies; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/Steeltoe.CloudFoundry.Connector.EF6Core.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | All 36 | 37 | 38 | 39 | 40 | 41 | stylecop.json 42 | Always 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Test 18 | { 19 | public class TestHelpers 20 | { 21 | public static string CreateTempFile(string contents) 22 | { 23 | var tempFile = Path.GetTempFileName(); 24 | File.WriteAllText(tempFile, contents); 25 | return tempFile; 26 | } 27 | 28 | public static Stream StringToStream(string str) 29 | { 30 | var memStream = new MemoryStream(); 31 | var textWriter = new StreamWriter(memStream); 32 | textWriter.Write(str); 33 | textWriter.Flush(); 34 | memStream.Seek(0, SeekOrigin.Begin); 35 | 36 | return memStream; 37 | } 38 | 39 | public static string StreamToString(Stream stream) 40 | { 41 | stream.Seek(0, SeekOrigin.Begin); 42 | var reader = new StreamReader(stream); 43 | 44 | return reader.ReadToEnd(); 45 | } 46 | 47 | public static string VCAP_APPLICATION = @" 48 | { 49 | 'limits': { 50 | 'fds': 16384, 51 | 'mem': 1024, 52 | 'disk': 1024 53 | }, 54 | 'application_name': 'spring-cloud-broker', 55 | 'application_uris': [ 56 | 'spring-cloud-broker.apps.testcloud.com' 57 | ], 58 | 'name': 'spring-cloud-broker', 59 | 'space_name': 'p-spring-cloud-services', 60 | 'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae', 61 | 'uris': [ 62 | 'spring-cloud-broker.apps.testcloud.com' 63 | ], 64 | 'users': null, 65 | 'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 66 | 'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 67 | 'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06' 68 | } 69 | }"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EF6Core.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EFCore.Test/GoodDbContext.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.EntityFrameworkCore; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.EFCore.Test 18 | { 19 | internal class GoodDbContext : DbContext 20 | { 21 | public GoodDbContext(DbContextOptions options) 22 | : base(options) 23 | { 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EFCore.Test/MySqlTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.MySql.Test 18 | { 19 | /// 20 | /// These tests can be found in Base, EF6 Autofac, EF6 Core and EF Core, for testing different nuget packages. 21 | /// This version should be testing the driver brought in by the Pomelo EF Core package 22 | /// Don't remove it unless you've got a better idea for making sure we work with multiple assemblies 23 | /// with conflicting names/types 24 | /// 25 | public class MySqlTypeLocatorTest 26 | { 27 | [Fact] 28 | public void Property_Can_Locate_ConnectionType() 29 | { 30 | // arrange -- handled by including a compatible MySql NuGet package 31 | 32 | // act 33 | var type = MySqlTypeLocator.MySqlConnection; 34 | 35 | // assert 36 | Assert.NotNull(type); 37 | } 38 | 39 | [Fact] 40 | public void Driver_Found_In_MySqlConnector_Assembly() 41 | { 42 | // arrange ~ narrow the assembly list to one specific nuget package 43 | var assemblies = MySqlTypeLocator.Assemblies; 44 | MySqlTypeLocator.Assemblies = new string[] { "MySqlConnector" }; 45 | 46 | // act 47 | var type = MySqlTypeLocator.MySqlConnection; 48 | 49 | // assert 50 | Assert.NotNull(type); 51 | MySqlTypeLocator.Assemblies = assemblies; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EFCore.Test/Steeltoe.CloudFoundry.Connector.EFCore.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | All 41 | 42 | 43 | 44 | 45 | 46 | stylecop.json 47 | Always 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EFCore.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Test 18 | { 19 | public class TestHelpers 20 | { 21 | public static string CreateTempFile(string contents) 22 | { 23 | var tempFile = Path.GetTempFileName(); 24 | File.WriteAllText(tempFile, contents); 25 | return tempFile; 26 | } 27 | 28 | public static Stream StringToStream(string str) 29 | { 30 | var memStream = new MemoryStream(); 31 | var textWriter = new StreamWriter(memStream); 32 | textWriter.Write(str); 33 | textWriter.Flush(); 34 | memStream.Seek(0, SeekOrigin.Begin); 35 | 36 | return memStream; 37 | } 38 | 39 | public static string StreamToString(Stream stream) 40 | { 41 | stream.Seek(0, SeekOrigin.Begin); 42 | var reader = new StreamReader(stream); 43 | 44 | return reader.ReadToEnd(); 45 | } 46 | 47 | public static string VCAP_APPLICATION = @" 48 | { 49 | 'limits': { 50 | 'fds': 16384, 51 | 'mem': 1024, 52 | 'disk': 1024 53 | }, 54 | 'application_name': 'spring-cloud-broker', 55 | 'application_uris': [ 56 | 'spring-cloud-broker.apps.testcloud.com' 57 | ], 58 | 'name': 'spring-cloud-broker', 59 | 'space_name': 'p-spring-cloud-services', 60 | 'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae', 61 | 'uris': [ 62 | 'spring-cloud-broker.apps.testcloud.com' 63 | ], 64 | 'users': null, 65 | 'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 66 | 'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 67 | 'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06' 68 | } 69 | }"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.Connector.EFCore.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorAutofac.Test/HystrixContainerBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using Steeltoe.CloudFoundry.Connector.Hystrix; 18 | using System; 19 | using Xunit; 20 | 21 | namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test 22 | { 23 | public class HystrixContainerBuilderExtensionsTest 24 | { 25 | [Fact] 26 | public void RegisterHystrixConnection_Requires_Builder() 27 | { 28 | // arrange 29 | IConfiguration config = new ConfigurationBuilder().Build(); 30 | 31 | // act & assert 32 | Assert.Throws(() => HystrixContainerBuilderExtensions.RegisterHystrixConnection(null, config)); 33 | } 34 | 35 | [Fact] 36 | public void RegisterHystrixConnection_Requires_Config() 37 | { 38 | // arrange 39 | ContainerBuilder cb = new ContainerBuilder(); 40 | 41 | // act & assert 42 | Assert.Throws(() => HystrixContainerBuilderExtensions.RegisterHystrixConnection(cb, null)); 43 | } 44 | 45 | [Fact] 46 | public void RegisterHystrixConnection_AddsToContainer() 47 | { 48 | // arrange 49 | ContainerBuilder container = new ContainerBuilder(); 50 | IConfiguration config = new ConfigurationBuilder().Build(); 51 | 52 | // act 53 | var regBuilder = HystrixContainerBuilderExtensions.RegisterHystrixConnection(container, config); 54 | var services = container.Build(); 55 | var hystrixFactory = services.Resolve(); 56 | 57 | // assert 58 | Assert.NotNull(hystrixFactory); 59 | Assert.IsType(hystrixFactory); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorAutofac.Test/MySqlTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.MySql.Test 18 | { 19 | /// 20 | /// These tests can be found in Base, EF6 Autofac, EF6 Core and EF Core, for testing different nuget packages. 21 | /// This version should be testing v8 of the Oracle driver 22 | /// Don't remove it unless you've got a better idea for making sure we work with multiple assemblies 23 | /// with conflicting names/types 24 | /// 25 | public class MySqlTypeLocatorTest 26 | { 27 | [Fact] 28 | public void Property_Can_Locate_ConnectionType() 29 | { 30 | // arrange -- handled by including a compatible MySql NuGet package 31 | 32 | // act 33 | var type = MySqlTypeLocator.MySqlConnection; 34 | 35 | // assert 36 | Assert.NotNull(type); 37 | } 38 | 39 | [Fact] 40 | public void Driver_Found_In_MySqlData_Assembly() 41 | { 42 | // arrange ~ narrow the assembly list to one specific nuget package 43 | var assemblies = MySqlTypeLocator.Assemblies; 44 | MySqlTypeLocator.Assemblies = new string[] { "MySql.Data" }; 45 | 46 | // act 47 | var type = MySqlTypeLocator.MySqlConnection; 48 | 49 | // assert 50 | Assert.NotNull(type); 51 | MySqlTypeLocator.Assemblies = assemblies; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorAutofac.Test/OAuthContainerBuilderExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Autofac; 16 | using Microsoft.Extensions.Configuration; 17 | using Microsoft.Extensions.Options; 18 | using Steeltoe.CloudFoundry.Connector; 19 | using Steeltoe.CloudFoundry.Connector.OAuth; 20 | using System; 21 | using Xunit; 22 | 23 | namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test 24 | { 25 | public class OAuthContainerBuilderExtensionsTest 26 | { 27 | [Fact] 28 | public void RegisterOAuthServiceOptions_Requires_Builder() 29 | { 30 | // arrange 31 | IConfiguration config = new ConfigurationBuilder().Build(); 32 | 33 | // act & assert 34 | Assert.Throws(() => OAuthContainerBuilderExtensions.RegisterOAuthServiceOptions(null, config)); 35 | } 36 | 37 | [Fact] 38 | public void RegisterOAuthServiceOptions_Requires_Config() 39 | { 40 | // arrange 41 | ContainerBuilder cb = new ContainerBuilder(); 42 | 43 | // act & assert 44 | Assert.Throws(() => OAuthContainerBuilderExtensions.RegisterOAuthServiceOptions(cb, null)); 45 | } 46 | 47 | [Fact] 48 | public void RegisterOAuthServiceOptions_AddsToContainer() 49 | { 50 | // arrange 51 | ContainerBuilder container = new ContainerBuilder(); 52 | IConfiguration config = new ConfigurationBuilder().Build(); 53 | 54 | // act 55 | var regBuilder = OAuthContainerBuilderExtensions.RegisterOAuthServiceOptions(container, config); 56 | var services = container.Build(); 57 | var options = services.Resolve>(); 58 | 59 | // assert 60 | Assert.NotNull(options); 61 | Assert.IsType>(options); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorAutofac.Test/Steeltoe.CloudFoundry.ConnectorAutofac.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net461 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | All 25 | 26 | 27 | 28 | 29 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 30 | 31 | 32 | 33 | stylecop.json 34 | Always 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | PreserveNewest 45 | 46 | 47 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/AbstractServiceConfigurationTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | using System; 17 | using System.IO; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.Test 21 | { 22 | public class AbstractServiceConfigurationTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfConfigNull() 26 | { 27 | // Arrange 28 | IConfiguration config = null; 29 | 30 | // Act and Assert 31 | var ex = Assert.Throws(() => new TestServiceConfiguration(config)); 32 | Assert.Contains(nameof(config), ex.Message); 33 | } 34 | 35 | [Fact] 36 | public void Constructor_BindsValues() 37 | { 38 | var appsettings = @" 39 | { 40 | 'test': 'myString' 41 | }"; 42 | 43 | var path = TestHelpers.CreateTempFile(appsettings); 44 | string directory = Path.GetDirectoryName(path); 45 | string fileName = Path.GetFileName(path); 46 | 47 | ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); 48 | configurationBuilder.SetBasePath(directory); 49 | configurationBuilder.AddJsonFile(fileName); 50 | var config = configurationBuilder.Build(); 51 | 52 | var sconfig = new TestServiceConfiguration(config); 53 | Assert.Equal("myString", sconfig.Test); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Cache/RedisCacheTestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Redis.Test 16 | { 17 | public static class RedisCacheTestHelpers 18 | { 19 | public static string SingleServerVCAP = @" 20 | { 21 | 'p-redis': [ 22 | { 23 | 'credentials': { 24 | 'host': '192.168.0.103', 25 | 'password': '133de7c8-9f3a-4df1-8a10-676ba7ddaa10', 26 | 'port': 60287 27 | }, 28 | 'syslog_drain_url': null, 29 | 'label': 'p-redis', 30 | 'provider': null, 31 | 'plan': 'shared-vm', 32 | 'name': 'myRedisService1', 33 | 'tags': [ 34 | 'pivotal', 35 | 'redis' 36 | ] 37 | } 38 | ] 39 | }"; 40 | 41 | public static string TwoServerVCAP = @" 42 | { 43 | 'p-redis': [ 44 | { 45 | 'credentials': { 46 | 'host': '192.168.0.103', 47 | 'password': '133de7c8-9f3a-4df1-8a10-676ba7ddaa10', 48 | 'port': 60287 49 | }, 50 | 'syslog_drain_url': null, 51 | 'label': 'p-redis', 52 | 'provider': null, 53 | 'plan': 'shared-vm', 54 | 'name': 'myRedisService1', 55 | 'tags': [ 56 | 'pivotal', 57 | 'redis' 58 | ] 59 | }, 60 | { 61 | 'credentials': { 62 | 'host': '192.168.0.103', 63 | 'password': '133de7c8-9f3a-4df1-8a10-676ba7ddaa10', 64 | 'port': 60287 65 | }, 66 | 'syslog_drain_url': null, 67 | 'label': 'p-redis', 68 | 'provider': null, 69 | 'plan': 'shared-vm', 70 | 'name': 'myRedisService2', 71 | 'tags': [ 72 | 'pivotal', 73 | 'redis' 74 | ] 75 | } 76 | ] 77 | }"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/CircuitBreaker/HystrixProviderConnectorFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using RabbitMQ.Client; 16 | using Steeltoe.CloudFoundry.Connector.Services; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.Hystrix.Test 21 | { 22 | public class HystrixProviderConnectorFactoryTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfConfigNull() 26 | { 27 | // Arrange 28 | HystrixProviderConnectorOptions config = null; 29 | HystrixRabbitMQServiceInfo si = null; 30 | 31 | // Act and Assert 32 | var ex = Assert.Throws(() => new HystrixProviderConnectorFactory(si, config, typeof(ConnectionFactory))); 33 | Assert.Contains(nameof(config), ex.Message); 34 | } 35 | 36 | [Fact] 37 | public void Create_ReturnsRabbitMQConnection() 38 | { 39 | HystrixProviderConnectorOptions config = new HystrixProviderConnectorOptions() 40 | { 41 | Server = "localhost", 42 | Port = 5672, 43 | Password = "password", 44 | Username = "username", 45 | VirtualHost = "vhost" 46 | }; 47 | HystrixRabbitMQServiceInfo si = new HystrixRabbitMQServiceInfo("MyId", "amqp://si_username:si_password@example.com:5672/si_vhost", false); 48 | var factory = new HystrixProviderConnectorFactory(si, config, typeof(ConnectionFactory)); 49 | var connection = factory.Create(null); 50 | Assert.NotNull(connection); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/ConnectorExceptionTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Xunit; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Test 19 | { 20 | public class ConnectorExceptionTest 21 | { 22 | [Fact] 23 | public void Constructor_CapturesMessage() 24 | { 25 | var ex = new ConnectorException("Test"); 26 | Assert.Equal("Test", ex.Message); 27 | 28 | var ex2 = new ConnectorException("Test2", new Exception()); 29 | Assert.Equal("Test2", ex2.Message); 30 | } 31 | 32 | [Fact] 33 | public void Constructor_CapturesNestedException() 34 | { 35 | var inner = new Exception(); 36 | var ex = new ConnectorException("Test2", inner); 37 | Assert.Equal(inner, ex.InnerException); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/DocumentDB/MongoDb/MongoDbTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.MongoDb.Test 18 | { 19 | public class MongoDbTypeLocatorTest 20 | { 21 | [Fact] 22 | public void Property_Can_Locate_ConnectionTypes() 23 | { 24 | // arrange -- handled by including a compatible MongoDB NuGet package 25 | 26 | // act 27 | var interfaceType = MongoDbTypeLocator.IMongoClient; 28 | var implementationType = MongoDbTypeLocator.MongoClient; 29 | var mongoUrlType = MongoDbTypeLocator.MongoUrl; 30 | 31 | // assert 32 | Assert.NotNull(interfaceType); 33 | Assert.NotNull(implementationType); 34 | Assert.NotNull(mongoUrlType); 35 | } 36 | 37 | [Fact] 38 | public void Throws_When_ConnectionType_NotFound() 39 | { 40 | // arrange 41 | var types = MongoDbTypeLocator.ConnectionInterfaceTypeNames; 42 | MongoDbTypeLocator.ConnectionInterfaceTypeNames = new string[] { "something-Wrong" }; 43 | 44 | // act 45 | var exception = Assert.Throws(() => MongoDbTypeLocator.IMongoClient); 46 | 47 | // assert 48 | Assert.Equal("Unable to find IMongoClient, are you missing a MongoDB driver?", exception.Message); 49 | 50 | // reset 51 | MongoDbTypeLocator.ConnectionInterfaceTypeNames = types; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/OAuth/OAuthConnectorFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using Xunit; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.OAuth.Test 19 | { 20 | public class OAuthConnectorFactoryTest 21 | { 22 | [Fact] 23 | public void Create_ReturnsOAuthOptions() 24 | { 25 | SsoServiceInfo si = new SsoServiceInfo("myId", "myClientId", "myClientSecret", "https://foo.bar"); 26 | OAuthConnectorOptions config = new OAuthConnectorOptions(); 27 | 28 | var factory = new OAuthConnectorFactory(si, config); 29 | var result = factory.Create(null); 30 | 31 | Assert.NotNull(result); 32 | var opts = result.Value; 33 | Assert.NotNull(opts); 34 | 35 | Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_AccessTokenUri, opts.AccessTokenUrl); 36 | Assert.Equal("myClientId", opts.ClientId); 37 | Assert.Equal("myClientSecret", opts.ClientSecret); 38 | Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_JwtTokenKey, opts.JwtKeyUrl); 39 | Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_CheckTokenUri, opts.TokenInfoUrl); 40 | Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_AuthorizationUri, opts.UserAuthorizationUrl); 41 | Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_UserInfoUri, opts.UserInfoUrl); 42 | Assert.NotNull(opts.Scope); 43 | Assert.Equal(0, opts.Scope.Count); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Queue/RabbitMQServiceConnectorFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using RabbitMQ.Client; 16 | using Steeltoe.CloudFoundry.Connector.Services; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.RabbitMQ.Test 21 | { 22 | public class RabbitMQServiceConnectorFactoryTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfConfigNull() 26 | { 27 | // Arrange 28 | RabbitMQProviderConnectorOptions config = null; 29 | RabbitMQServiceInfo si = null; 30 | 31 | // Act and Assert 32 | var ex = Assert.Throws(() => new RabbitMQProviderConnectorFactory(si, config, typeof(ConnectionFactory))); 33 | Assert.Contains(nameof(config), ex.Message); 34 | } 35 | 36 | [Fact] 37 | public void Create_ReturnsRabbitMQConnection() 38 | { 39 | RabbitMQProviderConnectorOptions config = new RabbitMQProviderConnectorOptions() 40 | { 41 | Server = "localhost", 42 | Port = 5672, 43 | Password = "password", 44 | Username = "username", 45 | VirtualHost = "vhost" 46 | }; 47 | RabbitMQServiceInfo si = new RabbitMQServiceInfo("MyId", "amqp://si_username:si_password@example.com:5672/si_vhost"); 48 | var factory = new RabbitMQProviderConnectorFactory(si, config, typeof(ConnectionFactory)); 49 | var connection = factory.Create(null); 50 | Assert.NotNull(connection); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Queue/RabbitMQTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.RabbitMQ.Test 18 | { 19 | public class RabbitMQTypeLocatorTest 20 | { 21 | [Fact] 22 | public void Property_Can_Locate_ConnectionTypes() 23 | { 24 | // arrange -- handled by including a compatible RabbitMQ NuGet package 25 | 26 | // act 27 | var interfaceType = RabbitMQTypeLocator.IConnectionFactory; 28 | var implementationType = RabbitMQTypeLocator.ConnectionFactory; 29 | var connectionType = RabbitMQTypeLocator.IConnection; 30 | 31 | // assert 32 | Assert.NotNull(interfaceType); 33 | Assert.NotNull(implementationType); 34 | Assert.NotNull(connectionType); 35 | } 36 | 37 | [Fact] 38 | public void Throws_When_ConnectionType_NotFound() 39 | { 40 | // arrange 41 | var types = RabbitMQTypeLocator.ConnectionInterfaceTypeNames; 42 | RabbitMQTypeLocator.ConnectionInterfaceTypeNames = new string[] { "something-Wrong" }; 43 | 44 | // act 45 | var exception = Assert.Throws(() => RabbitMQTypeLocator.IConnectionFactory); 46 | 47 | // assert 48 | Assert.Equal("Unable to find IConnectionFactory, are you missing the RabbitMQ.Client assembly?", exception.Message); 49 | 50 | // reset 51 | RabbitMQTypeLocator.ConnectionInterfaceTypeNames = types; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Relational/MySql/MySqlProviderConnectorFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using MySql.Data.MySqlClient; 16 | using Steeltoe.CloudFoundry.Connector.Services; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.MySql.Test 21 | { 22 | public class MySqlProviderConnectorFactoryTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfConfigNull() 26 | { 27 | // Arrange 28 | MySqlProviderConnectorOptions config = null; 29 | MySqlServiceInfo si = null; 30 | 31 | // Act and Assert 32 | var ex = Assert.Throws(() => new MySqlProviderConnectorFactory(si, config, typeof(MySqlConnection))); 33 | Assert.Contains(nameof(config), ex.Message); 34 | } 35 | 36 | [Fact] 37 | public void Create_ReturnsMySqlConnection() 38 | { 39 | MySqlProviderConnectorOptions config = new MySqlProviderConnectorOptions() 40 | { 41 | Server = "localhost", 42 | Port = 3306, 43 | Password = "password", 44 | Username = "username", 45 | Database = "database" 46 | }; 47 | MySqlServiceInfo si = new MySqlServiceInfo("MyId", "mysql://Dd6O1BPXUHdrmzbP:7E1LxXnlH2hhlPVt@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355"); 48 | var factory = new MySqlProviderConnectorFactory(si, config, typeof(MySqlConnection)); 49 | var connection = factory.Create(null); 50 | Assert.NotNull(connection); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Relational/PostgreSQL/PostgresProviderConnectorFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Npgsql; 16 | using Steeltoe.CloudFoundry.Connector.Services; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.PostgreSql.Test 21 | { 22 | public class PostgresProviderConnectorFactoryTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfConfigNull() 26 | { 27 | // Arrange 28 | PostgresProviderConnectorOptions config = null; 29 | PostgresServiceInfo si = null; 30 | 31 | // Act and Assert 32 | var ex = Assert.Throws(() => new PostgresProviderConnectorFactory(si, config, typeof(NpgsqlConnection))); 33 | Assert.Contains(nameof(config), ex.Message); 34 | } 35 | 36 | [Fact] 37 | public void Create_ReturnsPostgresConnection() 38 | { 39 | PostgresProviderConnectorOptions config = new PostgresProviderConnectorOptions() 40 | { 41 | Host = "localhost", 42 | Port = 3306, 43 | Password = "password", 44 | Username = "username", 45 | Database = "database" 46 | }; 47 | PostgresServiceInfo si = new PostgresServiceInfo("MyId", "postgres://Dd6O1BPXUHdrmzbP:7E1LxXnlH2hhlPVt@192.168.0.90:5432/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355"); 48 | var factory = new PostgresProviderConnectorFactory(si, config, typeof(NpgsqlConnection)); 49 | var connection = factory.Create(null); 50 | Assert.NotNull(connection); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Relational/PostgreSql/PostgreSqlTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.PostgreSql.Test 18 | { 19 | public class PostgreSqlTypeLocatorTest 20 | { 21 | [Fact] 22 | public void Property_Can_Locate_ConnectionType() 23 | { 24 | // arrange -- handled by including a compatible PostgreSql NuGet package 25 | 26 | // act 27 | var type = PostgreSqlTypeLocator.NpgsqlConnection; 28 | 29 | // assert 30 | Assert.NotNull(type); 31 | } 32 | 33 | [Fact] 34 | public void Throws_When_ConnectionType_NotFound() 35 | { 36 | // arrange 37 | var types = PostgreSqlTypeLocator.ConnectionTypeNames; 38 | PostgreSqlTypeLocator.ConnectionTypeNames = new string[] { "something-Wrong" }; 39 | 40 | // act 41 | var exception = Assert.Throws(() => PostgreSqlTypeLocator.NpgsqlConnection); 42 | 43 | // assert 44 | Assert.Equal("Unable to find NpgsqlConnection, are you missing a PostgreSQL ADO.NET assembly?", exception.Message); 45 | 46 | // reset 47 | PostgreSqlTypeLocator.ConnectionTypeNames = types; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Relational/SqlServer/SqlServerProviderConnectorFactoryTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using System; 17 | using System.Data.SqlClient; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.SqlServer.Test 21 | { 22 | public class SqlServerProviderConnectorFactoryTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfConfigNull() 26 | { 27 | // Arrange 28 | SqlServerProviderConnectorOptions config = null; 29 | 30 | // Act and Assert 31 | var ex = Assert.Throws(() => new SqlServerProviderConnectorFactory(null, config, typeof(SqlConnection))); 32 | Assert.Contains(nameof(config), ex.Message); 33 | } 34 | 35 | [Fact] 36 | public void Create_ReturnsSqlConnection() 37 | { 38 | SqlServerProviderConnectorOptions config = new SqlServerProviderConnectorOptions() 39 | { 40 | Server = "servername", 41 | Password = "password", 42 | Username = "username", 43 | Database = "database" 44 | }; 45 | SqlServerServiceInfo si = new SqlServerServiceInfo("MyId", "jdbc:sqlserver://servername:1433/databaseName=de5aa3a747c134b3d8780f8cc80be519e", "user", "pass"); 46 | var factory = new SqlServerProviderConnectorFactory(si, config, typeof(SqlConnection)); 47 | var connection = factory.Create(null); 48 | Assert.NotNull(connection); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Relational/SqlServer/SqlServerTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.SqlServer.Test 18 | { 19 | public class SqlServerTypeLocatorTest 20 | { 21 | [Fact] 22 | public void Property_Can_Locate_ConnectionType() 23 | { 24 | // arrange -- handled by including System.Data.SqlClient 25 | 26 | // act 27 | var type = SqlServerTypeLocator.SqlConnection; 28 | 29 | // assert 30 | Assert.NotNull(type); 31 | } 32 | 33 | [Fact] 34 | public void Throws_When_ConnectionType_NotFound() 35 | { 36 | // arrange 37 | var types = SqlServerTypeLocator.ConnectionTypeNames; 38 | SqlServerTypeLocator.ConnectionTypeNames = new string[] { "something-Wrong" }; 39 | 40 | // act 41 | var exception = Assert.Throws(() => SqlServerTypeLocator.SqlConnection); 42 | 43 | // assert 44 | Assert.Equal("Unable to find SqlConnection, are you missing a Microsoft SQL Server ADO.NET assembly?", exception.Message); 45 | 46 | // reset 47 | SqlServerTypeLocator.ConnectionTypeNames = types; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/DB2ServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class DB2ServiceInfoTest 20 | { 21 | [Fact] 22 | public void Constructor_CreatesExpected() 23 | { 24 | string uri = "db2://Dd6O1BPXUHdrmzbP:7E1LxXnlH2hhlPVt@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355"; 25 | DB2ServiceInfo r1 = new DB2ServiceInfo("myId", uri); 26 | 27 | Assert.Equal("myId", r1.Id); 28 | Assert.Equal("db2", r1.Scheme); 29 | Assert.Equal("192.168.0.90", r1.Host); 30 | Assert.Equal(3306, r1.Port); 31 | Assert.Equal("7E1LxXnlH2hhlPVt", r1.Password); 32 | Assert.Equal("Dd6O1BPXUHdrmzbP", r1.UserName); 33 | Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", r1.Path); 34 | Assert.Null(r1.Query); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/EurekaServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class EurekaServiceInfoTest 20 | { 21 | [Fact] 22 | public void Constructor_CreatesExpected() 23 | { 24 | string uri = "https://username:password@hostname:1111/"; 25 | string clientId = "clientId"; 26 | string clientSecret = "clientSecret"; 27 | string accessTokenUri = "https://p-spring-cloud-services.uaa.my-cf.com/oauth/token"; 28 | EurekaServiceInfo r1 = new EurekaServiceInfo("myId", uri, clientId, clientSecret, accessTokenUri); 29 | 30 | Assert.Equal("myId", r1.Id); 31 | Assert.Equal("https", r1.Scheme); 32 | Assert.Equal("hostname", r1.Host); 33 | Assert.Equal(1111, r1.Port); 34 | Assert.Equal("password", r1.Password); 35 | Assert.Equal("username", r1.UserName); 36 | Assert.Equal("clientId", r1.ClientId); 37 | Assert.Equal("clientSecret", r1.ClientSecret); 38 | Assert.Equal("https://p-spring-cloud-services.uaa.my-cf.com/oauth/token", r1.TokenUri); 39 | Assert.Equal("https://username:password@hostname:1111/", r1.Uri); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/MySqlServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class MySqlServiceInfoTest 20 | { 21 | [Fact] 22 | public void Constructor_CreatesExpected() 23 | { 24 | string uri = "mysql://Dd6O1BPXUHdrmzbP:7E1LxXnlH2hhlPVt@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355?reconnect=true"; 25 | MySqlServiceInfo r1 = new MySqlServiceInfo("myId", uri); 26 | 27 | Assert.Equal("myId", r1.Id); 28 | Assert.Equal("mysql", r1.Scheme); 29 | Assert.Equal("192.168.0.90", r1.Host); 30 | Assert.Equal(3306, r1.Port); 31 | Assert.Equal("7E1LxXnlH2hhlPVt", r1.Password); 32 | Assert.Equal("Dd6O1BPXUHdrmzbP", r1.UserName); 33 | Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", r1.Path); 34 | Assert.Equal("reconnect=true", r1.Query); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/OracleServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class OracleServiceInfoTest 20 | { 21 | [Fact] 22 | public void Constructor_CreatesExpected() 23 | { 24 | string uri = "oracle://Dd6O1BPXUHdrmzbP:7E1LxXnlH2hhlPVt@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355?reconnect=true"; 25 | OracleServiceInfo r1 = new OracleServiceInfo("myId", uri); 26 | 27 | Assert.Equal("myId", r1.Id); 28 | Assert.Equal("oracle", r1.Scheme); 29 | Assert.Equal("192.168.0.90", r1.Host); 30 | Assert.Equal(3306, r1.Port); 31 | Assert.Equal("7E1LxXnlH2hhlPVt", r1.Password); 32 | Assert.Equal("Dd6O1BPXUHdrmzbP", r1.UserName); 33 | Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", r1.Path); 34 | Assert.Equal("reconnect=true", r1.Query); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/PostgresServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class PostgresServiceInfoTest 20 | { 21 | [Fact] 22 | public void Constructor_CreatesExpected() 23 | { 24 | string uri = "postgres://Dd6O1BPXUHdrmzbP:7E1LxXnlH2hhlPVt@192.168.0.90:3306/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355?reconnect=true"; 25 | PostgresServiceInfo r1 = new PostgresServiceInfo("myId", uri); 26 | 27 | Assert.Equal("myId", r1.Id); 28 | Assert.Equal("postgres", r1.Scheme); 29 | Assert.Equal("192.168.0.90", r1.Host); 30 | Assert.Equal(3306, r1.Port); 31 | Assert.Equal("7E1LxXnlH2hhlPVt", r1.Password); 32 | Assert.Equal("Dd6O1BPXUHdrmzbP", r1.UserName); 33 | Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", r1.Path); 34 | Assert.Equal("reconnect=true", r1.Query); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/ServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.App; 16 | using Steeltoe.CloudFoundry.Connector.App.Test; 17 | using System; 18 | using Xunit; 19 | 20 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 21 | { 22 | public class ServiceInfoTest 23 | { 24 | [Fact] 25 | public void Constructor_ThrowsIfIdNull() 26 | { 27 | string id = null; 28 | 29 | // Act and Assert 30 | var ex = Assert.Throws(() => new TestServiceInfo(id)); 31 | Assert.Contains(nameof(id), ex.Message); 32 | } 33 | 34 | [Fact] 35 | public void Constructor_InitializesValues() 36 | { 37 | ApplicationInstanceInfo info = new ApplicationInstanceInfo(ApplicationInstanceInfoTest.MakeCloudFoundryApplicationOptions()); 38 | var si = new TestServiceInfo("id", info); 39 | Assert.Equal("id", si.Id); 40 | Assert.Equal(info, si.ApplicationInfo); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/SqlServerInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class SqlServerInfoTest 20 | { 21 | [Fact] 22 | public void Constructor_CreatesExpected() 23 | { 24 | string uri = "jdbc:sqlserver://192.168.0.90:1433/databaseName=de5aa3a747c134b3d8780f8cc80be519e"; 25 | SqlServerServiceInfo r1 = new SqlServerServiceInfo("myId", uri, "Dd6O1BPXUHdrmzbP", "7E1LxXnlH2hhlPVt"); 26 | 27 | Assert.Equal("myId", r1.Id); 28 | Assert.Equal("sqlserver", r1.Scheme); 29 | Assert.Equal("192.168.0.90", r1.Host); 30 | Assert.Equal(1433, r1.Port); 31 | Assert.Equal("7E1LxXnlH2hhlPVt", r1.Password); 32 | Assert.Equal("Dd6O1BPXUHdrmzbP", r1.UserName); 33 | Assert.Equal("de5aa3a747c134b3d8780f8cc80be519e", r1.Path); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/SsoServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.Services; 16 | using Xunit; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Test.Services 19 | { 20 | public class SsoServiceInfoTest 21 | { 22 | [Fact] 23 | public void Constructor_CreatesExpected() 24 | { 25 | string clientId = "clientId"; 26 | string clientSecret = "clientSecret"; 27 | string authDomain = "https://p-spring-cloud-services.uaa.my-cf.com/oauth/token"; 28 | SsoServiceInfo r1 = new SsoServiceInfo("myId", clientId, clientSecret, authDomain); 29 | Assert.Equal("myId", r1.Id); 30 | Assert.Equal("clientId", r1.ClientId); 31 | Assert.Equal("clientSecret", r1.ClientSecret); 32 | Assert.Equal("https://p-spring-cloud-services.uaa.my-cf.com/oauth/token", r1.AuthDomain); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/TagsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | public class TagsTest 20 | { 21 | private static Tags emptyTags = new Tags(); 22 | 23 | [Fact] 24 | public void ContainsOne() 25 | { 26 | Tags tags = new Tags(new string[] { "test1", "test2" }); 27 | Assert.True(tags.ContainsOne(new string[] { "test1", "testx" })); 28 | Assert.True(tags.ContainsOne(new string[] { "testx", "test2" })); 29 | Assert.False(tags.ContainsOne(new string[] { "testx", "testy" })); 30 | } 31 | 32 | [Fact] 33 | public void ContainsOne_WithEmptyTags() 34 | { 35 | Assert.False(emptyTags.ContainsOne(new string[] { "test" })); 36 | } 37 | 38 | [Fact] 39 | public void Contains() 40 | { 41 | Tags tags = new Tags(new string[] { "test1", "test2" }); 42 | Assert.True(tags.Contains("test1")); 43 | Assert.True(tags.Contains("test2")); 44 | Assert.False(tags.Contains("testx")); 45 | } 46 | 47 | [Fact] 48 | public void Contains_WithEmptyTags() 49 | { 50 | Assert.False(emptyTags.Contains("test")); 51 | } 52 | 53 | [Fact] 54 | public void StartsWith() 55 | { 56 | Tags tags = new Tags("test"); 57 | Assert.True(tags.StartsWith("test-123")); 58 | Assert.False(tags.StartsWith("abcd")); 59 | } 60 | 61 | [Fact] 62 | public void StartsWith_WithEmptyTags() 63 | { 64 | Assert.False(emptyTags.StartsWith("test")); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/TestServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.CloudFoundry.Connector.App; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 18 | { 19 | internal class TestServiceInfo : ServiceInfo 20 | { 21 | public TestServiceInfo(string id, ApplicationInstanceInfo info) 22 | : base(id, info) 23 | { 24 | } 25 | 26 | public TestServiceInfo(string id) 27 | : base(id, null) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/TestServiceInfoFactory.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Steeltoe.Extensions.Configuration.CloudFoundry; 16 | using System; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 19 | { 20 | internal class TestServiceInfoFactory : ServiceInfoFactory 21 | { 22 | public TestServiceInfoFactory(Tags tags, string scheme) 23 | : base(tags, scheme) 24 | { 25 | } 26 | 27 | public TestServiceInfoFactory(Tags tags, string[] schemes) 28 | : base(tags, schemes) 29 | { 30 | } 31 | 32 | public override IServiceInfo Create(Service binding) 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/TestUriServiceInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 16 | { 17 | internal class TestUriServiceInfo : UriServiceInfo 18 | { 19 | public TestUriServiceInfo(string id, string uri) 20 | : base(id, uri) 21 | { 22 | } 23 | 24 | public TestUriServiceInfo(string id, string scheme, string host, int port, string username, string password, string path) 25 | : base(id, scheme, host, port, username, password, path) 26 | { 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Services/UriServiceInfoTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Xunit; 17 | 18 | namespace Steeltoe.CloudFoundry.Connector.Services.Test 19 | { 20 | public class UriServiceInfoTest 21 | { 22 | [Fact] 23 | public void Constructor_CreatesExpected() 24 | { 25 | string uri = "mysql://joe:joes_password@localhost:1527/big_db"; 26 | UriServiceInfo r1 = new TestUriServiceInfo("myId", "mysql", "localhost", 1527, "joe", "joes_password", "big_db"); 27 | UriServiceInfo r2 = new TestUriServiceInfo("myId", uri); 28 | 29 | Assert.Equal("myId", r1.Id); 30 | Assert.Equal("mysql", r1.Scheme); 31 | Assert.Equal("localhost", r1.Host); 32 | Assert.Equal(1527, r1.Port); 33 | Assert.Equal("joe", r1.UserName); 34 | Assert.Equal("joes_password", r1.Password); 35 | Assert.Equal("big_db", r1.Path); 36 | Assert.Null(r1.Query); 37 | 38 | Assert.Equal("myId", r2.Id); 39 | Assert.Equal("mysql", r2.Scheme); 40 | Assert.Equal("localhost", r2.Host); 41 | Assert.Equal(1527, r2.Port); 42 | Assert.Equal("joe", r2.UserName); 43 | Assert.Equal("joes_password", r2.Password); 44 | Assert.Equal("big_db", r2.Path); 45 | Assert.Null(r2.Query); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/Steeltoe.CloudFoundry.ConnectorBase.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | All 41 | 42 | 43 | 44 | 45 | 46 | stylecop.json 47 | Always 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Test 18 | { 19 | public class TestHelpers 20 | { 21 | public static string CreateTempFile(string contents) 22 | { 23 | var tempFile = Path.GetTempFileName(); 24 | File.WriteAllText(tempFile, contents); 25 | return tempFile; 26 | } 27 | 28 | public static Stream StringToStream(string str) 29 | { 30 | var memStream = new MemoryStream(); 31 | var textWriter = new StreamWriter(memStream); 32 | textWriter.Write(str); 33 | textWriter.Flush(); 34 | memStream.Seek(0, SeekOrigin.Begin); 35 | 36 | return memStream; 37 | } 38 | 39 | public static string StreamToString(Stream stream) 40 | { 41 | stream.Seek(0, SeekOrigin.Begin); 42 | var reader = new StreamReader(stream); 43 | 44 | return reader.ReadToEnd(); 45 | } 46 | 47 | public static string VCAP_APPLICATION = @" 48 | { 49 | 'limits': { 50 | 'fds': 16384, 51 | 'mem': 1024, 52 | 'disk': 1024 53 | }, 54 | 'application_name': 'spring-cloud-broker', 55 | 'application_uris': [ 56 | 'spring-cloud-broker.apps.testcloud.com' 57 | ], 58 | 'name': 'spring-cloud-broker', 59 | 'space_name': 'p-spring-cloud-services', 60 | 'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae', 61 | 'uris': [ 62 | 'spring-cloud-broker.apps.testcloud.com' 63 | ], 64 | 'users': null, 65 | 'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 66 | 'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 67 | 'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06' 68 | } 69 | }"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/TestServiceConfiguration.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Microsoft.Extensions.Configuration; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Test 18 | { 19 | internal class TestServiceConfiguration : AbstractServiceConnectorOptions 20 | { 21 | public TestServiceConfiguration(IConfiguration config) 22 | : base(config) 23 | { 24 | } 25 | 26 | public string Test { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorBase.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorCore.Test/ConnectorIOptionsTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Test 18 | { 19 | public class ConnectorIOptionsTest 20 | { 21 | [Fact] 22 | public void Value_Returns_Expected() 23 | { 24 | var myOpt = new MyOption(); 25 | var opt = new ConnectorIOptions(myOpt); 26 | 27 | Assert.NotNull(opt.Value); 28 | Assert.True(opt.Value == myOpt); 29 | } 30 | } 31 | 32 | internal class MyOption 33 | { 34 | public MyOption() 35 | { 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorCore.Test/MySqlTypeLocatorTest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Xunit; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.MySql.Test 18 | { 19 | /// 20 | /// These tests can be found in Base, EF6 Autofac, EF6 Core and EF Core, for testing different nuget packages. 21 | /// This version should be testing v6 of the Oracle driver 22 | /// Don't remove it unless you've got a better idea for making sure we work with multiple assemblies 23 | /// with conflicting names/types 24 | /// 25 | public class MySqlTypeLocatorTest 26 | { 27 | [Fact] 28 | public void Property_Can_Locate_ConnectionType() 29 | { 30 | // arrange -- handled by including a compatible MySql NuGet package 31 | 32 | // act 33 | var type = MySqlTypeLocator.MySqlConnection; 34 | 35 | // assert 36 | Assert.NotNull(type); 37 | } 38 | 39 | [Fact] 40 | public void Driver_Found_In_MySqlData_Assembly() 41 | { 42 | // arrange ~ narrow the assembly list to one specific nuget package 43 | var assemblies = MySqlTypeLocator.Assemblies; 44 | MySqlTypeLocator.Assemblies = new string[] { "MySql.Data" }; 45 | 46 | // act 47 | var type = MySqlTypeLocator.MySqlConnection; 48 | 49 | // assert 50 | Assert.NotNull(type); 51 | MySqlTypeLocator.Assemblies = assemblies; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorCore.Test/Steeltoe.CloudFoundry.ConnectorCore.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp2.0;netcoreapp2.1;net461 5 | 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | stylecop.json 48 | Always 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorCore.Test/TestHelpers.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the original author or authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System.IO; 16 | 17 | namespace Steeltoe.CloudFoundry.Connector.Test 18 | { 19 | public class TestHelpers 20 | { 21 | public static string CreateTempFile(string contents) 22 | { 23 | var tempFile = Path.GetTempFileName(); 24 | File.WriteAllText(tempFile, contents); 25 | return tempFile; 26 | } 27 | 28 | public static Stream StringToStream(string str) 29 | { 30 | var memStream = new MemoryStream(); 31 | var textWriter = new StreamWriter(memStream); 32 | textWriter.Write(str); 33 | textWriter.Flush(); 34 | memStream.Seek(0, SeekOrigin.Begin); 35 | 36 | return memStream; 37 | } 38 | 39 | public static string StreamToString(Stream stream) 40 | { 41 | stream.Seek(0, SeekOrigin.Begin); 42 | var reader = new StreamReader(stream); 43 | 44 | return reader.ReadToEnd(); 45 | } 46 | 47 | public static string VCAP_APPLICATION = @" 48 | { 49 | 'limits': { 50 | 'fds': 16384, 51 | 'mem': 1024, 52 | 'disk': 1024 53 | }, 54 | 'application_name': 'spring-cloud-broker', 55 | 'application_uris': [ 56 | 'spring-cloud-broker.apps.testcloud.com' 57 | ], 58 | 'name': 'spring-cloud-broker', 59 | 'space_name': 'p-spring-cloud-services', 60 | 'space_id': '65b73473-94cc-4640-b462-7ad52838b4ae', 61 | 'uris': [ 62 | 'spring-cloud-broker.apps.testcloud.com' 63 | ], 64 | 'users': null, 65 | 'version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 66 | 'application_version': '07e112f7-2f71-4f5a-8a34-db51dbed30a3', 67 | 'application_id': '798c2495-fe75-49b1-88da-b81197f2bf06' 68 | } 69 | }"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /test/Steeltoe.CloudFoundry.ConnectorCore.Test/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeTestCollections": false 4 | } -------------------------------------------------------------------------------- /versions.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | --------------------------------------------------------------------------------