Adding Autofac extensions and tests, don't reference EFCore package in non-EFCore test project, fix 2.x second delay in ConnectionMultiplexer tests, refactor Redis Type location to shared class [#151373153]

This commit is contained in:
Tim Hess 2018-02-12 07:44:54 -06:00
Родитель 7ff99df236
Коммит d9aaf1216e
30 изменённых файлов: 1154 добавлений и 49 удалений

Просмотреть файл

@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9BB0395E-B595-4B95-89ED-F55AF12B4EE7}"
EndProject
@ -52,6 +52,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.CloudFoundry.Conne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.CloudFoundry.ConnectorBase.Test", "test\Steeltoe.CloudFoundry.ConnectorBase.Test\Steeltoe.CloudFoundry.ConnectorBase.Test.csproj", "{B40DE919-FBC0-4CC6-B36F-98364FCA4203}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.CloudFoundry.ConnectorAutofac", "src\Steeltoe.CloudFoundry.ConnectorAutofac\Steeltoe.CloudFoundry.ConnectorAutofac.csproj", "{73EEC113-97AC-4F74-8099-2C0EDEAA9596}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Steeltoe.CloudFoundry.ConnectorAutofac.Test", "test\Steeltoe.CloudFoundry.ConnectorAutofac.Test\Steeltoe.CloudFoundry.ConnectorAutofac.Test.csproj", "{59F8BEF1-D25D-4B18-A060-97E4C5B37600}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -158,6 +162,30 @@ Global
{B40DE919-FBC0-4CC6-B36F-98364FCA4203}.Release|x64.Build.0 = Release|Any CPU
{B40DE919-FBC0-4CC6-B36F-98364FCA4203}.Release|x86.ActiveCfg = Release|Any CPU
{B40DE919-FBC0-4CC6-B36F-98364FCA4203}.Release|x86.Build.0 = Release|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Debug|x64.ActiveCfg = Debug|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Debug|x64.Build.0 = Debug|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Debug|x86.ActiveCfg = Debug|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Debug|x86.Build.0 = Debug|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Release|Any CPU.Build.0 = Release|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Release|x64.ActiveCfg = Release|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Release|x64.Build.0 = Release|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Release|x86.ActiveCfg = Release|Any CPU
{73EEC113-97AC-4F74-8099-2C0EDEAA9596}.Release|x86.Build.0 = Release|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Debug|x64.ActiveCfg = Debug|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Debug|x64.Build.0 = Debug|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Debug|x86.ActiveCfg = Debug|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Debug|x86.Build.0 = Debug|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Release|Any CPU.Build.0 = Release|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Release|x64.ActiveCfg = Release|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Release|x64.Build.0 = Release|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Release|x86.ActiveCfg = Release|Any CPU
{59F8BEF1-D25D-4B18-A060-97E4C5B37600}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -171,6 +199,8 @@ Global
{D7296042-50AA-4570-BD5F-15DEAD416EDF} = {1CEE3AF7-DC06-4BBE-B28D-62FB1BD4A7A5}
{F9A2807C-292F-49EB-B23A-FBB04527BA5C} = {9BB0395E-B595-4B95-89ED-F55AF12B4EE7}
{B40DE919-FBC0-4CC6-B36F-98364FCA4203} = {1CEE3AF7-DC06-4BBE-B28D-62FB1BD4A7A5}
{73EEC113-97AC-4F74-8099-2C0EDEAA9596} = {9BB0395E-B595-4B95-89ED-F55AF12B4EE7}
{59F8BEF1-D25D-4B18-A060-97E4C5B37600} = {1CEE3AF7-DC06-4BBE-B28D-62FB1BD4A7A5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {112EBBFA-82B9-483E-B258-8611B70B3A3A}

Просмотреть файл

@ -6,6 +6,7 @@
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
<AspNetCoreTestVersion>2.0.0</AspNetCoreTestVersion>
<AspNetCoreMvcTestVersion>2.0.0</AspNetCoreMvcTestVersion>
<AutofacVersion>4.6.1</AutofacVersion>
<CoreFxVersion>4.4.0</CoreFxVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<EF6Version>6.1.3</EF6Version>
@ -18,6 +19,7 @@
<NpgsqlEFCoreVersion>2.0.0</NpgsqlEFCoreVersion>
<RabbitClientVersion>5.0.1</RabbitClientVersion>
<MySqlVersion>6.9.10</MySqlVersion>
<SqlClientVersion>4.4.2</SqlClientVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>

Просмотреть файл

@ -6,6 +6,7 @@
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
<AspNetCoreTestVersion>2.0.0</AspNetCoreTestVersion>
<AspNetCoreMvcTestVersion>2.0.0</AspNetCoreMvcTestVersion>
<AutofacVersion>4.6.1</AutofacVersion>
<CoreFxVersion>4.4.0</CoreFxVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<EF6Version>6.1.3</EF6Version>
@ -18,6 +19,7 @@
<NpgsqlEFCoreVersion>2.0.0</NpgsqlEFCoreVersion>
<RabbitClientVersion>5.0.1</RabbitClientVersion>
<MySqlVersion>6.9.10</MySqlVersion>
<SqlClientVersion>4.4.2</SqlClientVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>

Просмотреть файл

@ -16,6 +16,7 @@
<NpgsqlEFCoreVersion>1.1.1</NpgsqlEFCoreVersion>
<RabbitClientVersion>4.1.3</RabbitClientVersion>
<MySqlVersion>6.9.9</MySqlVersion>
<SqlClientVersion>4.4.2</SqlClientVersion>
<JsonNetVersion>9.0.1</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>

Просмотреть файл

@ -6,6 +6,7 @@
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
<AspNetCoreTestVersion>2.0.0</AspNetCoreTestVersion>
<AspNetCoreMvcTestVersion>2.0.0</AspNetCoreMvcTestVersion>
<AutofacVersion>4.6.1</AutofacVersion>
<CoreFxVersion>4.4.0</CoreFxVersion>
<StyleCopVersion>1.0.2</StyleCopVersion>
<EF6Version>6.1.3</EF6Version>
@ -18,6 +19,7 @@
<NpgsqlVersion>3.2.5</NpgsqlVersion>
<RabbitClientVersion>5.0.1</RabbitClientVersion>
<MySqlVersion>6.9.10</MySqlVersion>
<SqlClientVersion>4.4.2</SqlClientVersion>
<JsonNetVersion>10.0.3</JsonNetVersion>
<TestSdkVersion>15.5.0</TestSdkVersion>
<XunitVersion>2.3.1</XunitVersion>

Просмотреть файл

@ -0,0 +1,65 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.Hystrix;
using Steeltoe.CloudFoundry.Connector.Services;
using System;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class HystrixContainerBuilderExtensions
{
private static string[] rabbitAssemblies = new string[] { "RabbitMQ.Client" };
private static string[] rabbitTypeNames = new string[] { "RabbitMQ.Client.ConnectionFactory" };
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterHystrixConnection(this ContainerBuilder container, IConfiguration config, string serviceName = null)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type rabbitFactory = ConnectorHelpers.FindType(rabbitAssemblies, rabbitTypeNames);
if (rabbitFactory == null)
{
throw new ConnectorException("Unable to find RabbitMQ ConnectionFactory type. RabbitMQ.Client assembly may be missing");
}
HystrixRabbitMQServiceInfo info;
if (serviceName == null)
{
info = config.GetSingletonServiceInfo<HystrixRabbitMQServiceInfo>();
}
else
{
info = config.GetRequiredServiceInfo<HystrixRabbitMQServiceInfo>(serviceName);
}
HystrixProviderConnectorOptions hystrixConfig = new HystrixProviderConnectorOptions(config);
HystrixProviderConnectorFactory factory = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory);
return container.Register(c => factory.Create(null)).As<HystrixConnectionFactory>();
}
}
}

Просмотреть файл

@ -0,0 +1,55 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.MySql;
using Steeltoe.CloudFoundry.Connector.Services;
using System;
using System.Data;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class MySqlContainerBuilderExtensions
{
private static string[] mySqlAssemblies = new string[] { "MySql.Data", "MySqlConnector" };
private static string[] mySqlTypeNames = new string[] { "MySql.Data.MySqlClient.MySqlConnection" };
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterMySqlConnection(this ContainerBuilder container, IConfiguration config)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type mySqlConnection = ConnectorHelpers.FindType(mySqlAssemblies, mySqlTypeNames);
if (mySqlConnection == null)
{
throw new ConnectorException("Unable to find MySqlConnection, are you missing a MySql reference?");
}
MySqlProviderConnectorOptions mySqlConfig = new MySqlProviderConnectorOptions(config);
MySqlServiceInfo info = config.GetSingletonServiceInfo<MySqlServiceInfo>();
MySqlProviderConnectorFactory factory = new MySqlProviderConnectorFactory(info, mySqlConfig, mySqlConnection);
return container.Register(c => factory.Create(null)).As<IDbConnection>();
}
}
}

Просмотреть файл

@ -0,0 +1,56 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.OAuth;
using Steeltoe.CloudFoundry.Connector.Services;
using System;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class OAuthContainerBuilderExtensions
{
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterOAuthServiceOptions(this ContainerBuilder container, IConfiguration config, string serviceName = null)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
OAuthConnectorOptions oauthConfig = new OAuthConnectorOptions(config);
SsoServiceInfo info;
if (serviceName == null)
{
info = config.GetSingletonServiceInfo<SsoServiceInfo>();
}
else
{
info = config.GetRequiredServiceInfo<SsoServiceInfo>(serviceName);
}
OAuthConnectorFactory factory = new OAuthConnectorFactory(info, oauthConfig);
return container.Register(c => factory.Create(null)).As<IOptions<OAuthServiceOptions>>();
}
}
}

Просмотреть файл

@ -0,0 +1,55 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.PostgreSql;
using Steeltoe.CloudFoundry.Connector.Services;
using System;
using System.Data;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class PostgreSqlContainerBuilderExtensions
{
private static string[] postgreSqlAssemblies = new string[] { "Npgsql" };
private static string[] postgreSqlTypeNames = new string[] { "Npgsql.NpgsqlConnection" };
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterPostgreSqlConnection(this ContainerBuilder container, IConfiguration config)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type postgreSqlConnection = ConnectorHelpers.FindType(postgreSqlAssemblies, postgreSqlTypeNames);
if (postgreSqlConnection == null)
{
throw new ConnectorException("Unable to find NpgsqlConnection, are you missing a reference to Npgsql?");
}
var postgreSqlConfig = new PostgresProviderConnectorOptions(config);
PostgresServiceInfo info = config.GetSingletonServiceInfo<PostgresServiceInfo>();
PostgresProviderConnectorFactory factory = new PostgresProviderConnectorFactory(info, postgreSqlConfig, postgreSqlConnection);
return container.Register(c => factory.Create(null)).As<IDbConnection>();
}
}
}

Просмотреть файл

@ -0,0 +1,66 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.RabbitMQ;
using Steeltoe.CloudFoundry.Connector.Services;
using System;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class RabbitMQContainerBuilderExtensions
{
private static string[] rabbitMQAssemblies = new string[] { "RabbitMQ.Client" };
private static string[] rabbitMQInterfaceTypeNames = new string[] { "RabbitMQ.Client.IConnectionFactory" };
private static string[] rabbitMQImplementationTypeNames = new string[] { "RabbitMQ.Client.ConnectionFactory" };
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterRabbitMQConnection(this ContainerBuilder container, IConfiguration config, string serviceName = null)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type rabbitMQInterfaceType = ConnectorHelpers.FindType(rabbitMQAssemblies, rabbitMQInterfaceTypeNames);
Type rabbitMQImplementationType = ConnectorHelpers.FindType(rabbitMQAssemblies, rabbitMQImplementationTypeNames);
if (rabbitMQInterfaceType == null || rabbitMQImplementationType == null)
{
throw new ConnectorException("Unable to find ConnectionFactory, are you missing RabbitMQ assembly");
}
RabbitMQServiceInfo info;
if (serviceName == null)
{
info = config.GetSingletonServiceInfo<RabbitMQServiceInfo>();
}
else
{
info = config.GetRequiredServiceInfo<RabbitMQServiceInfo>(serviceName);
}
RabbitMQProviderConnectorOptions rabbitMQConfig = new RabbitMQProviderConnectorOptions(config);
RabbitMQProviderConnectorFactory factory = new RabbitMQProviderConnectorFactory(info, rabbitMQConfig, rabbitMQImplementationType);
return container.Register(c => factory.Create(null)).As(rabbitMQInterfaceType, rabbitMQImplementationType);
}
}
}

Просмотреть файл

@ -0,0 +1,107 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.Redis;
using Steeltoe.CloudFoundry.Connector.Services;
using Steeltoe.CloudFoundry.ConnectorBase.Cache;
using System;
using System.Reflection;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class RedisContainerBuilderExtensions
{
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterDistributedRedisCache(
this ContainerBuilder container,
IConfiguration config,
string serviceName = null)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type redisInterface = RedisTypeLocator.MicrosoftRedisInterface;
Type redisImplementation = RedisTypeLocator.MicrosoftRedisImplementation;
Type redisOptions = RedisTypeLocator.MicrosoftRedisOptions;
if (redisInterface == null || redisImplementation == null || redisOptions == null)
{
throw new ConnectorException("Unable to find required Redis types, are you missing the Microsoft.Extensions.Caching.Redis Nuget package?");
}
RedisServiceInfo info;
if (serviceName != null)
{
info = config.GetRequiredServiceInfo<RedisServiceInfo>(serviceName);
}
else
{
info = config.GetSingletonServiceInfo<RedisServiceInfo>();
}
RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config);
RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, null);
return container.Register(c => factory.Create(null)).As(redisInterface, redisImplementation);
}
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterRedisConnectionMultiplexer(
this ContainerBuilder container,
IConfiguration config,
string serviceName = null)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type redisInterface = RedisTypeLocator.StackExchangeRedisInterface;
Type redisImplementation = RedisTypeLocator.StackExchangeRedisImplementation;
Type redisOptions = RedisTypeLocator.StackExchangeRedisOptions;
MethodInfo initializer = RedisTypeLocator.StackExchangeInitializer;
if (redisInterface == null || redisImplementation == null || redisOptions == null || initializer == null)
{
throw new ConnectorException("Unable to find required Redis types, are you missing a StackExchange.Redis Nuget Package?");
}
RedisServiceInfo info;
if (serviceName != null)
{
info = config.GetRequiredServiceInfo<RedisServiceInfo>(serviceName);
}
else
{
info = config.GetSingletonServiceInfo<RedisServiceInfo>();
}
RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config);
RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, redisImplementation, redisOptions, initializer ?? null);
return container.Register(c => factory.Create(null)).As(redisInterface, redisImplementation);
}
}
}

Просмотреть файл

@ -0,0 +1,55 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Autofac.Builder;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.Services;
using Steeltoe.CloudFoundry.Connector.SqlServer;
using System;
using System.Data;
namespace Steeltoe.CloudFoundry.ConnectorAutofac
{
public static class SqlServerContainerBuilderExtensions
{
private static string[] sqlServerAssemblies = new string[] { "System.Data.SqlClient" };
private static string[] sqlServerTypeNames = new string[] { "System.Data.SqlClient.SqlConnection" };
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> RegisterSqlServerConnection(this ContainerBuilder container, IConfiguration config)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
Type sqlServerConnection = ConnectorHelpers.FindType(sqlServerAssemblies, sqlServerTypeNames);
if (sqlServerConnection == null)
{
throw new ConnectorException("Unable to find System.Data.SqlClient.SqlConnection, are you missing a System.Data.SqlClient reference?");
}
var sqlServerConfig = new SqlServerProviderConnectorOptions(config);
var info = config.GetSingletonServiceInfo<SqlServerServiceInfo>();
var factory = new SqlServerProviderConnectorFactory(info, sqlServerConfig, sqlServerConnection);
return container.Register(c => factory.Create(null)).As<IDbConnection>();
}
}
}

Просмотреть файл

@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\versions.props" />
<PropertyGroup>
<Description>CloudFoundry Connector Extensions for Autofac</Description>
<VersionPrefix>$(SteeltoeVersion)</VersionPrefix>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Authors>Pivotal;dtillman</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Steeltoe.CloudFoundry.ConnectorAutofac</AssemblyName>
<PackageId>Steeltoe.CloudFoundry.ConnectorAutofac</PackageId>
<PackageTags>CloudFoundry;ASPNET;Autofac</PackageTags>
<PackageIconUrl>https://steeltoe.io/images/transparent.png</PackageIconUrl>
<PackageProjectUrl>https://steeltoe.io</PackageProjectUrl>
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Steeltoe.CloudFoundry.ConnectorAutofac.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition="'$(CI_BUILD)' == ''">
<ProjectReference Include="..\Steeltoe.CloudFoundry.ConnectorBase\Steeltoe.CloudFoundry.ConnectorBase.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="$(AutofacVersion)" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopVersion)">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(CI_BUILD)' == 'True'">
<PackageReference Include="Steeltoe.CloudFoundry.ConnectorBase" Version="$(SteeltoeVersion)$(SteeltoeVersionSuffix)" />
</ItemGroup>
<PropertyGroup>
<NoWarn>SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json">
<Link>stylecop.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,50 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Steeltoe.CloudFoundry.Connector;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
namespace Steeltoe.CloudFoundry.ConnectorBase.Cache
{
public static class RedisTypeLocator
{
private static string[] msftRedisAssemblies = new string[] { "Microsoft.Extensions.Caching.Abstractions", "Microsoft.Extensions.Caching.Redis" };
private static string[] msftRedisInterfaceTypeNames = new string[] { "Microsoft.Extensions.Caching.Distributed.IDistributedCache" };
private static string[] msftRedisImplementationTypeNames = new string[] { "Microsoft.Extensions.Caching.Redis.RedisCache" };
private static string[] msftRedisOptionNames = new string[] { "Microsoft.Extensions.Caching.Redis.RedisCacheOptions" };
private static string[] stackExchangeRedisAssemblies = new string[] { "StackExchange.Redis", "StackExchange.Redis.StrongName" };
private static string[] stackExchangeRedisInterfaceTypeNames = new string[] { "StackExchange.Redis.IConnectionMultiplexer" };
private static string[] stackExchangeRedisImplementationTypeNames = new string[] { "StackExchange.Redis.ConnectionMultiplexer" };
private static string[] stackExchangeRedisOptionNames = new string[] { "StackExchange.Redis.ConfigurationOptions" };
public static Type MicrosoftRedisInterface => ConnectorHelpers.FindType(msftRedisAssemblies, msftRedisInterfaceTypeNames);
public static Type MicrosoftRedisImplementation => ConnectorHelpers.FindType(msftRedisAssemblies, msftRedisImplementationTypeNames);
public static Type MicrosoftRedisOptions => ConnectorHelpers.FindType(msftRedisAssemblies, msftRedisOptionNames);
public static Type StackExchangeRedisInterface => ConnectorHelpers.FindType(stackExchangeRedisAssemblies, stackExchangeRedisInterfaceTypeNames);
public static Type StackExchangeRedisImplementation => ConnectorHelpers.FindType(stackExchangeRedisAssemblies, stackExchangeRedisImplementationTypeNames);
public static Type StackExchangeRedisOptions => ConnectorHelpers.FindType(stackExchangeRedisAssemblies, stackExchangeRedisOptionNames);
public static MethodInfo StackExchangeInitializer =>
ConnectorHelpers.FindMethod(StackExchangeRedisImplementation, "Connect", new Type[] { StackExchangeRedisOptions, typeof(TextWriter) });
}
}

Просмотреть файл

@ -20,12 +20,7 @@ namespace Steeltoe.CloudFoundry.Connector.Hystrix
{
public HystrixConnectionFactory(object realFactory)
{
if (realFactory == null)
{
throw new ArgumentNullException(nameof(realFactory));
}
ConnectionFactory = realFactory;
ConnectionFactory = realFactory ?? throw new ArgumentNullException(nameof(realFactory));
}
public object ConnectionFactory { get; private set; }

Просмотреть файл

@ -29,19 +29,9 @@ namespace Steeltoe.CloudFoundry.Connector.Hystrix
public HystrixProviderConnectorFactory(HystrixRabbitMQServiceInfo sinfo, HystrixProviderConnectorOptions config, Type connectFactory)
{
if (config == null)
{
throw new ArgumentNullException(nameof(config));
}
if (connectFactory == null)
{
throw new ArgumentNullException(nameof(connectFactory));
}
_info = sinfo;
_config = config;
_type = connectFactory;
_config = config ?? throw new ArgumentNullException(nameof(config));
_type = connectFactory ?? throw new ArgumentNullException(nameof(connectFactory));
_setUri = FindSetUriMethod(_type);
if (_setUri == null)
{

Просмотреть файл

@ -16,6 +16,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Steeltoe.CloudFoundry.Connector.Services;
using Steeltoe.CloudFoundry.ConnectorBase.Cache;
using System;
using System.IO;
using System.Reflection;
@ -195,37 +196,26 @@ namespace Steeltoe.CloudFoundry.Connector.Redis
private static void DoAddIDistributedCache(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
{
string[] redisAssemblies = new string[] { "Microsoft.Extensions.Caching.Abstractions", "Microsoft.Extensions.Caching.Redis" };
string[] redisInterfaceTypeNames = new string[] { "Microsoft.Extensions.Caching.Distributed.IDistributedCache" };
string[] redisImplementationTypeNames = new string[] { "Microsoft.Extensions.Caching.Redis.RedisCache" };
string[] redisOptionNames = new string[] { "Microsoft.Extensions.Caching.Redis.RedisCacheOptions" };
Type redisInterface = ConnectorHelpers.FindType(redisAssemblies, redisInterfaceTypeNames);
Type redisConnection = ConnectorHelpers.FindType(redisAssemblies, redisImplementationTypeNames);
Type redisOptions = ConnectorHelpers.FindType(redisAssemblies, redisOptionNames);
if (redisInterface == null || redisConnection == null || redisOptions == null)
Type interfaceType = RedisTypeLocator.MicrosoftRedisInterface;
Type connectionType = RedisTypeLocator.MicrosoftRedisImplementation;
Type optionsType = RedisTypeLocator.MicrosoftRedisOptions;
if (interfaceType == null || connectionType == null || optionsType == null)
{
throw new ConnectorException("Unable to find required Redis types, are you missing the Microsoft.Extensions.Caching.Redis Nuget package?");
}
RedisCacheConnectorOptions redisConfig = new RedisCacheConnectorOptions(config);
RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, redisConnection, redisOptions, null);
services.Add(new ServiceDescriptor(redisInterface, factory.Create, contextLifetime));
services.Add(new ServiceDescriptor(redisConnection, factory.Create, contextLifetime));
RedisServiceConnectorFactory factory = new RedisServiceConnectorFactory(info, redisConfig, connectionType, optionsType, null);
services.Add(new ServiceDescriptor(interfaceType, factory.Create, contextLifetime));
services.Add(new ServiceDescriptor(connectionType, factory.Create, contextLifetime));
}
private static void DoAddConnectionMultiplexer(IServiceCollection services, RedisServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
{
string[] redisAssemblies = new string[] { "StackExchange.Redis", "StackExchange.Redis.StrongName" };
string[] redisInterfaceTypeNames = new string[] { "StackExchange.Redis.IConnectionMultiplexer" };
string[] redisImplementationTypeNames = new string[] { "StackExchange.Redis.ConnectionMultiplexer" };
string[] redisOptionNames = new string[] { "StackExchange.Redis.ConfigurationOptions" };
Type redisInterface = ConnectorHelpers.FindType(redisAssemblies, redisInterfaceTypeNames);
Type redisImplementation = ConnectorHelpers.FindType(redisAssemblies, redisImplementationTypeNames);
Type redisOptions = ConnectorHelpers.FindType(redisAssemblies, redisOptionNames);
MethodInfo initializer = ConnectorHelpers.FindMethod(redisImplementation, "Connect", new Type[] { redisOptions, typeof(TextWriter) });
Type redisInterface = RedisTypeLocator.StackExchangeRedisInterface;
Type redisImplementation = RedisTypeLocator.StackExchangeRedisImplementation;
Type redisOptions = RedisTypeLocator.StackExchangeRedisOptions;
MethodInfo initializer = RedisTypeLocator.StackExchangeInitializer;
if (redisInterface == null || redisImplementation == null || redisOptions == null || initializer == null)
{

Просмотреть файл

@ -24,7 +24,6 @@ namespace Steeltoe.CloudFoundry.Connector.SqlServer
public static class SqlServerProviderServiceCollectionExtensions
{
private static string[] sqlServerAssemblies = new string[] { "System.Data.SqlClient" };
private static string[] sqlServerTypeNames = new string[] { "System.Data.SqlClient.SqlConnection" };
/// <summary>
@ -90,7 +89,7 @@ namespace Steeltoe.CloudFoundry.Connector.SqlServer
Type sqlServerConnection = ConnectorHelpers.FindType(sqlServerAssemblies, sqlServerTypeNames);
if (sqlServerConnection == null)
{
throw new ConnectorException("Unable to find SqlServerConnection, are you missing SqlServer ADO.NET assembly");
throw new ConnectorException("Unable to find System.Data.SqlClient.SqlConnection, are you missing a reference to System.Data.SqlClient?");
}
SqlServerProviderConnectorOptions sqlServerConfig = new SqlServerProviderConnectorOptions(config);

Просмотреть файл

@ -0,0 +1,62 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Configuration;
using Steeltoe.CloudFoundry.Connector.Hystrix;
using System;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class HystrixContainerBuilderExtensionsTest
{
[Fact]
public void RegisterHystrixConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => HystrixContainerBuilderExtensions.RegisterHystrixConnection(null, config));
}
[Fact]
public void RegisterHystrixConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => HystrixContainerBuilderExtensions.RegisterHystrixConnection(cb, null));
}
[Fact]
public void RegisterHystrixConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = HystrixContainerBuilderExtensions.RegisterHystrixConnection(container, config);
var services = container.Build();
var hystrixFactory = services.Resolve<HystrixConnectionFactory>();
// assert
Assert.NotNull(hystrixFactory);
Assert.IsType<HystrixConnectionFactory>(hystrixFactory);
}
}
}

Просмотреть файл

@ -0,0 +1,63 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Configuration;
using MySql.Data.MySqlClient;
using System;
using System.Data;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class MySqlContainerBuilderExtensionsTest
{
[Fact]
public void RegisterMySqlConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => MySqlContainerBuilderExtensions.RegisterMySqlConnection(null, config));
}
[Fact]
public void RegisterMySqlConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => MySqlContainerBuilderExtensions.RegisterMySqlConnection(cb, null));
}
[Fact]
public void RegisterMySqlConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = MySqlContainerBuilderExtensions.RegisterMySqlConnection(container, config);
var services = container.Build();
var dbConn = services.Resolve<IDbConnection>();
// assert
Assert.NotNull(dbConn);
Assert.IsType<MySqlConnection>(dbConn);
}
}
}

Просмотреть файл

@ -0,0 +1,64 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Steeltoe.CloudFoundry.Connector;
using Steeltoe.CloudFoundry.Connector.OAuth;
using System;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class OAuthContainerBuilderExtensionsTest
{
[Fact]
public void RegisterOAuthServiceOptions_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => OAuthContainerBuilderExtensions.RegisterOAuthServiceOptions(null, config));
}
[Fact]
public void RegisterOAuthServiceOptions_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => OAuthContainerBuilderExtensions.RegisterOAuthServiceOptions(cb, null));
}
[Fact]
public void RegisterOAuthServiceOptions_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = OAuthContainerBuilderExtensions.RegisterOAuthServiceOptions(container, config);
var services = container.Build();
var options = services.Resolve<IOptions<OAuthServiceOptions>>();
// assert
Assert.NotNull(options);
Assert.IsType<ConnectorIOptions<OAuthServiceOptions>>(options);
}
}
}

Просмотреть файл

@ -0,0 +1,67 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Configuration;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class PostgreSqlContainerBuilderExtensionsTest
{
[Fact]
public void RegisterPostgreSqlConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => PostgreSqlContainerBuilderExtensions.RegisterPostgreSqlConnection(null, config));
}
[Fact]
public void RegisterPostgreSqlConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => PostgreSqlContainerBuilderExtensions.RegisterPostgreSqlConnection(cb, null));
}
[Fact]
public void RegisterPostgreSqlConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = PostgreSqlContainerBuilderExtensions.RegisterPostgreSqlConnection(container, config);
var services = container.Build();
var dbConn = services.Resolve<IDbConnection>();
// assert
Assert.NotNull(dbConn);
Assert.IsType<NpgsqlConnection>(dbConn);
}
}
}

Просмотреть файл

@ -0,0 +1,65 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Configuration;
using RabbitMQ.Client;
using System;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class RabbitMQContainerBuilderExtensionsTest
{
[Fact]
public void RegisterRabbitMQConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => RabbitMQContainerBuilderExtensions.RegisterRabbitMQConnection(null, config));
}
[Fact]
public void RegisterRabbitMQConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => RabbitMQContainerBuilderExtensions.RegisterRabbitMQConnection(cb, null));
}
[Fact]
public void RegisterRabbitMQConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = RabbitMQContainerBuilderExtensions.RegisterRabbitMQConnection(container, config);
var services = container.Build();
var rabbitMQIFactory = services.Resolve<IConnectionFactory>();
var rabbitMQFactory = services.Resolve<ConnectionFactory>();
// assert
Assert.NotNull(rabbitMQIFactory);
Assert.NotNull(rabbitMQFactory);
Assert.IsType<ConnectionFactory>(rabbitMQIFactory);
Assert.IsType<ConnectionFactory>(rabbitMQFactory);
}
}
}

Просмотреть файл

@ -0,0 +1,116 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.Configuration;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class RedisContainerBuilderExtensionsTest
{
[Fact]
public void RegisterRedisCacheConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => RedisContainerBuilderExtensions.RegisterDistributedRedisCache(null, config));
}
[Fact]
public void RegisterRedisCacheConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => RedisContainerBuilderExtensions.RegisterDistributedRedisCache(cb, null));
}
[Fact]
public void RegisterRedisCacheConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = RedisContainerBuilderExtensions.RegisterDistributedRedisCache(container, config);
var services = container.Build();
var redisCache = services.Resolve<RedisCache>();
var redisCacheFromI = services.Resolve<IDistributedCache>();
// assert
Assert.NotNull(redisCache);
Assert.IsType<RedisCache>(redisCache);
Assert.NotNull(redisCacheFromI);
Assert.IsType<RedisCache>(redisCacheFromI);
}
[Fact]
public void RegisterRedisConnectionMultiplexerConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => RedisContainerBuilderExtensions.RegisterRedisConnectionMultiplexer(null, config));
}
[Fact]
public void RegisterRedisConnectionMultiplexerConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => RedisContainerBuilderExtensions.RegisterRedisConnectionMultiplexer(cb, null));
}
[Fact]
public void RegisterRedisConnectionMultiplexerConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
var appsettings = new Dictionary<string, string>()
{
["redis:client:abortOnConnectFail"] = "false",
["redis:client:connectTimeout"] = "1"
};
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(appsettings);
var config = configurationBuilder.Build();
// act
var regBuilder = RedisContainerBuilderExtensions.RegisterRedisConnectionMultiplexer(container, config);
var services = container.Build();
var redisConnectionMultiplexer = services.Resolve<ConnectionMultiplexer>();
var redisIConnectionMultiplexer = services.Resolve<IConnectionMultiplexer>();
// assert
Assert.NotNull(redisConnectionMultiplexer);
Assert.IsType<ConnectionMultiplexer>(redisConnectionMultiplexer);
Assert.NotNull(redisIConnectionMultiplexer);
Assert.IsType<ConnectionMultiplexer>(redisIConnectionMultiplexer);
}
}
}

Просмотреть файл

@ -0,0 +1,63 @@
// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Autofac;
using Microsoft.Extensions.Configuration;
using System;
using System.Data;
using System.Data.SqlClient;
using Xunit;
namespace Steeltoe.CloudFoundry.ConnectorAutofac.Test
{
public class SqlServerContainerBuilderExtensionsTest
{
[Fact]
public void RegisterSqlServerConnection_Requires_Builder()
{
// arrange
IConfiguration config = new ConfigurationBuilder().Build();
// act & assert
Assert.Throws<ArgumentNullException>(() => SqlServerContainerBuilderExtensions.RegisterSqlServerConnection(null, config));
}
[Fact]
public void RegisterSqlServerConnection_Requires_Config()
{
// arrange
ContainerBuilder cb = new ContainerBuilder();
// act & assert
Assert.Throws<ArgumentNullException>(() => SqlServerContainerBuilderExtensions.RegisterSqlServerConnection(cb, null));
}
[Fact]
public void RegisterSqlServerConnection_AddsToContainer()
{
// arrange
ContainerBuilder container = new ContainerBuilder();
IConfiguration config = new ConfigurationBuilder().Build();
// act
var regBuilder = SqlServerContainerBuilderExtensions.RegisterSqlServerConnection(container, config);
var services = container.Build();
var dbConn = services.Resolve<IDbConnection>();
// assert
Assert.NotNull(dbConn);
Assert.IsType<SqlConnection>(dbConn);
}
}
}

Просмотреть файл

@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\versions.props" />
<PropertyGroup>
<TargetFrameworks>net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="$(AspNetCoreTestVersion)" />
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(PomeloEFCoreVersion)" />
<PackageReference Include="RabbitMQ.Client" Version="$(RabbitClientVersion)" />
<PackageReference Include="StackExchange.Redis.StrongName" Version="$(StackExchangeVersion)" />
<PackageReference Include="System.Data.SqlClient" Version="$(SqlClientVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitStudioVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XunitVersion)" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopVersion)">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<NoWarn>SA1101;SA1124;SA1201;SA1309;SA1310;SA1401;SA1600;SA1652;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json">
<Link>stylecop.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Steeltoe.CloudFoundry.ConnectorAutofac\Steeltoe.CloudFoundry.ConnectorAutofac.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Просмотреть файл

@ -63,7 +63,8 @@ namespace Steeltoe.CloudFoundry.Connector.Redis.Test
Port = 1234,
Password = "password",
InstanceName = "instanceId",
AbortOnConnectFail = false
AbortOnConnectFail = false,
ConnectTimeout = 1
};
RedisServiceInfo si = new RedisServiceInfo("myId", "127.0.0.1", 4321, "sipassword")
{

Просмотреть файл

@ -22,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFCoreTestVersion)" />
<PackageReference Include="System.Data.SqlClient" Version="$(SqlClientVersion)" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="$(AspNetCoreTestVersion)" />
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(PomeloEFCoreVersion)" />

Просмотреть файл

@ -194,7 +194,8 @@ namespace Steeltoe.CloudFoundry.Connector.Redis.Test
["redis:client:host"] = "127.0.0.1",
["redis:client:port"] = "1234",
["redis:client:password"] = "password",
["redis:client:abortOnConnectFail"] = "false"
["redis:client:abortOnConnectFail"] = "false",
["redis:client:connectTimeout"] = "1"
};
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

Просмотреть файл

@ -24,14 +24,13 @@
<ItemGroup>
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="$(SteeltoeConfigVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EFCoreTestVersion)" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="$(AspNetCoreTestVersion)" />
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(PomeloEFCoreVersion)" />
<PackageReference Include="RabbitMQ.Client" Version="$(RabbitClientVersion)" />
<PackageReference Include="StackExchange.Redis.StrongName" Version="$(StackExchangeVersion)" />
<PackageReference Include="System.Data.SqlClient" Version="$(SqlClientVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitStudioVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />