添加mysql单元测试
This commit is contained in:
parent
866a103932
commit
9740f897ec
|
@ -32,6 +32,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCore.MySql.3x", "sr
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCore.MySql.2x", "src2x\ShardingCore.MySql.2x\ShardingCore.MySql.2x.csproj", "{0CF88F0B-6CCB-49B5-B41D-CDC193B51581}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCore.Test50.MySql", "test\ShardingCore.Test50.MySql\ShardingCore.Test50.MySql.csproj", "{C8FAB96F-F13E-4094-883C-2D38D39EE4A3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -49,6 +51,7 @@ Global
|
|||
{10308339-FF5C-43AB-9208-627B6E2FBBDB} = {490FAE47-4476-4508-B216-505FC850447F}
|
||||
{954C4CA2-9CF4-4C2C-8DE6-180DD8202E38} = {62AAE0FE-4099-4A48-AA3C-F76F14C62655}
|
||||
{0CF88F0B-6CCB-49B5-B41D-CDC193B51581} = {679E6084-0C45-4807-BFEE-D2FDA44B2188}
|
||||
{C8FAB96F-F13E-4094-883C-2D38D39EE4A3} = {CC2C88C0-65F2-445D-BE78-973B840FE281}
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3CAF09A6-6ABD-41D9-BA57-9A822B8095F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
|
@ -95,5 +98,9 @@ Global
|
|||
{0CF88F0B-6CCB-49B5-B41D-CDC193B51581}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0CF88F0B-6CCB-49B5-B41D-CDC193B51581}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0CF88F0B-6CCB-49B5-B41D-CDC193B51581}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C8FAB96F-F13E-4094-883C-2D38D39EE4A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C8FAB96F-F13E-4094-883C-2D38D39EE4A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C8FAB96F-F13E-4094-883C-2D38D39EE4A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C8FAB96F-F13E-4094-883C-2D38D39EE4A3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"MySql": {
|
||||
"ConnectionString": "server=localhost;port=3306;user=root;password=123456;database=ShardingCoreDB;sslMode=None;"
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<DefineConstants>TRACE;DEBUG;EFCORE5MYSQL;</DefineConstants>
|
||||
<AssemblyName>ShardingCore.Test50</AssemblyName>
|
||||
<RootNamespace>ShardingCore.Test50</RootNamespace>
|
||||
<PackageId>ShardingCore.Test50</PackageId>
|
||||
<Product>ShardingCore.Test50</Product>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="Xunit.DependencyInjection" Version="7.1.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ShardingCore.MySql\ShardingCore.MySql.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\test\ShardingCore.Test50\**\*.cs" />
|
||||
<Compile Remove="..\..\test\ShardingCore.Test50\obj\**" />
|
||||
<Compile Remove="..\..\test\ShardingCore.Test50\bin\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Configs\DbConfig.json">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -3,6 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<DefineConstants>TRACE;DEBUG;EFCORE5SQLSERVER;</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -2,15 +2,22 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using ShardingCore.DbContexts.VirtualDbContexts;
|
||||
using ShardingCore.Extensions;
|
||||
using ShardingCore.SqlServer;
|
||||
using ShardingCore.Test50.Domain.Entities;
|
||||
using ShardingCore.Test50.Shardings;
|
||||
|
||||
#if EFCORE5SQLSERVER
|
||||
using ShardingCore.SqlServer;
|
||||
#endif
|
||||
#if EFCORE5MYSQL
|
||||
using ShardingCore.MySql;
|
||||
#endif
|
||||
|
||||
namespace ShardingCore.Test50
|
||||
{
|
||||
/*
|
||||
|
@ -21,7 +28,7 @@ namespace ShardingCore.Test50
|
|||
*/
|
||||
public class Startup
|
||||
{
|
||||
// 自定义 host 构建
|
||||
// // 自定义 host 构建
|
||||
public void ConfigureHost(IHostBuilder hostBuilder)
|
||||
{
|
||||
hostBuilder
|
||||
|
@ -37,6 +44,7 @@ namespace ShardingCore.Test50
|
|||
// ConfigureServices(HostBuilderContext hostBuilderContext, IServiceCollection services)
|
||||
public void ConfigureServices(IServiceCollection services, HostBuilderContext hostBuilderContext)
|
||||
{
|
||||
#if EFCORE5SQLSERVER
|
||||
services.AddShardingSqlServer(o =>
|
||||
{
|
||||
o.ConnectionString = hostBuilderContext.Configuration.GetSection("SqlServer")["ConnectionString"];
|
||||
|
@ -47,6 +55,20 @@ namespace ShardingCore.Test50
|
|||
config.EnsureCreated = true;
|
||||
});
|
||||
});
|
||||
#endif
|
||||
#if EFCORE5MYSQL
|
||||
services.AddShardingMySql(o =>
|
||||
{
|
||||
o.ConnectionString = hostBuilderContext.Configuration.GetSection("MySql")["ConnectionString"];
|
||||
o.ServerVersion = new MySqlServerVersion(new Version());
|
||||
o.AddSharding<SysUserModVirtualRoute>();
|
||||
o.AddSharding<SysUserRangeVirtualRoute>();
|
||||
o.CreateIfNotExists((provider, config) =>
|
||||
{
|
||||
config.EnsureCreated = true;
|
||||
});
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
// 可以添加要用到的方法参数,会自动从注册的服务中获取服务实例,类似于 asp.net core 里 Configure 方法
|
||||
|
|
Loading…
Reference in New Issue