优化单元测试名称
This commit is contained in:
parent
b0ab0815e2
commit
9d2f4cc7e0
|
@ -28,7 +28,7 @@ namespace ShardingCore.MySql
|
||||||
*/
|
*/
|
||||||
public static class DIExtension
|
public static class DIExtension
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddShardingSqlServer(this IServiceCollection services, Action<MySqlOptions> configure)
|
public static IServiceCollection AddShardingMySql(this IServiceCollection services, Action<MySqlOptions> configure)
|
||||||
{
|
{
|
||||||
if (configure == null)
|
if (configure == null)
|
||||||
throw new ArgumentNullException($"AddScfSqlServerProvider :{nameof(configure)}");
|
throw new ArgumentNullException($"AddScfSqlServerProvider :{nameof(configure)}");
|
||||||
|
|
|
@ -38,27 +38,22 @@ namespace ShardingCore.Core.VirtualRoutes.Abstractions
|
||||||
_logger.LogWarning($"没有找到对应的匹配需要进行多表扫描:ShardingOperator:[{shardingOperator}]");
|
_logger.LogWarning($"没有找到对应的匹配需要进行多表扫描:ShardingOperator:[{shardingOperator}]");
|
||||||
return tail => true;
|
return tail => true;
|
||||||
//throw new NotSupportedException(xxxx);
|
//throw new NotSupportedException(xxxx);
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.GreaterThan:
|
case ShardingOperatorEnum.GreaterThan:
|
||||||
return tail =>int.Parse(tail) > int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
return tail =>int.Parse(tail) > int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
||||||
case ShardingOperatorEnum.GreaterThanOrEqual:
|
case ShardingOperatorEnum.GreaterThanOrEqual:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>int.Parse(tail) >= int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
return tail =>int.Parse(tail) >= int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.LessThan:
|
case ShardingOperatorEnum.LessThan:
|
||||||
return tail =>int.Parse(tail) < int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
return tail =>int.Parse(tail) < int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
||||||
case ShardingOperatorEnum.LessThanOrEqual:
|
case ShardingOperatorEnum.LessThanOrEqual:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>int.Parse(tail) <= int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
return tail =>int.Parse(tail) <= int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.Equal:
|
case ShardingOperatorEnum.Equal:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>int.Parse(tail) == int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
return tail =>int.Parse(tail) == int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.NotEqual:
|
case ShardingOperatorEnum.NotEqual:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>int.Parse(tail) != int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
return tail =>int.Parse(tail) != int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(shardingOperator), shardingOperator, null);
|
throw new ArgumentOutOfRangeException(nameof(shardingOperator), shardingOperator, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,25 +44,20 @@ namespace ShardingCore.Core.VirtualRoutes.Abstractions
|
||||||
_logger.LogWarning($"没有找到对应的匹配需要进行多表扫描:ShardingOperator:[{shardingOperator}]");
|
_logger.LogWarning($"没有找到对应的匹配需要进行多表扫描:ShardingOperator:[{shardingOperator}]");
|
||||||
return tail => true;
|
return tail => true;
|
||||||
//throw new NotSupportedException(xxxx);
|
//throw new NotSupportedException(xxxx);
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.GreaterThan:
|
case ShardingOperatorEnum.GreaterThan:
|
||||||
case ShardingOperatorEnum.GreaterThanOrEqual:
|
case ShardingOperatorEnum.GreaterThanOrEqual:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>String.Compare(tail, GetWeekTableTail(shardingKey), StringComparison.Ordinal) >= 0;
|
return tail =>String.Compare(tail, GetWeekTableTail(shardingKey), StringComparison.Ordinal) >= 0;
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.LessThan:
|
case ShardingOperatorEnum.LessThan:
|
||||||
case ShardingOperatorEnum.LessThanOrEqual:
|
case ShardingOperatorEnum.LessThanOrEqual:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>String.Compare(tail, GetWeekTableTail(shardingKey), StringComparison.Ordinal) <= 0;
|
return tail =>String.Compare(tail, GetWeekTableTail(shardingKey), StringComparison.Ordinal) <= 0;
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.Equal:
|
case ShardingOperatorEnum.Equal:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>tail == GetWeekTableTail(shardingKey);
|
return tail =>tail == GetWeekTableTail(shardingKey);
|
||||||
break;
|
|
||||||
case ShardingOperatorEnum.NotEqual:
|
case ShardingOperatorEnum.NotEqual:
|
||||||
//yyyyMMdd
|
//yyyyMMdd
|
||||||
return tail =>tail != GetWeekTableTail(shardingKey);
|
return tail =>tail != GetWeekTableTail(shardingKey);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(shardingOperator), shardingOperator, null);
|
throw new ArgumentOutOfRangeException(nameof(shardingOperator), shardingOperator, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateSqlVirtualTableNotFoundException(string? message) : base(message)
|
public CreateSqlVirtualTableNotFoundException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreateSqlVirtualTableNotFoundException(string? message, Exception? innerException) : base(message, innerException)
|
public CreateSqlVirtualTableNotFoundException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableRouteNotMatchException(string? message) : base(message)
|
public QueryableRouteNotMatchException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryableRouteNotMatchException(string? message, Exception? innerException) : base(message, innerException)
|
public QueryableRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingEntityTypeConfiguration404Exception(string? message) : base(message)
|
public ShardingEntityTypeConfiguration404Exception(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingEntityTypeConfiguration404Exception(string? message, Exception? innerException) : base(message, innerException)
|
public ShardingEntityTypeConfiguration404Exception(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingKeyRouteMoreException(string? message) : base(message)
|
public ShardingKeyRouteMoreException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingKeyRouteMoreException(string? message, Exception? innerException) : base(message, innerException)
|
public ShardingKeyRouteMoreException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingKeyRouteNotMatchException(string? message) : base(message)
|
public ShardingKeyRouteNotMatchException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingKeyRouteNotMatchException(string? message, Exception? innerException) : base(message, innerException)
|
public ShardingKeyRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingOwnerNotFoundException(string? message) : base(message)
|
public ShardingOwnerNotFoundException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingOwnerNotFoundException(string? message, Exception? innerException) : base(message, innerException)
|
public ShardingOwnerNotFoundException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingTransactionException(string? message) : base(message)
|
public ShardingTransactionException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShardingTransactionException(string? message, Exception? innerException) : base(message, innerException)
|
public ShardingTransactionException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualRouteNotFoundException(string? message) : base(message)
|
public VirtualRouteNotFoundException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualRouteNotFoundException(string? message, Exception? innerException) : base(message, innerException)
|
public VirtualRouteNotFoundException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualRouteNotMatchException(string? message) : base(message)
|
public VirtualRouteNotMatchException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualRouteNotMatchException(string? message, Exception? innerException) : base(message, innerException)
|
public VirtualRouteNotMatchException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,11 @@ namespace ShardingCore.Exceptions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualTableNotFoundException(string? message) : base(message)
|
public VirtualTableNotFoundException(string message) : base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualTableNotFoundException(string? message, Exception? innerException) : base(message, innerException)
|
public VirtualTableNotFoundException(string message, Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace ShardingCore
|
||||||
{
|
{
|
||||||
_tableCreator.CreateTable(virtualTable.EntityType, tail);
|
_tableCreator.CreateTable(virtualTable.EntityType, tail);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_logger.LogWarning($"table :{virtualTable.GetOriginalTableName()}{shardingConfig.TailPrefix}{tail} will created");
|
_logger.LogWarning($"table :{virtualTable.GetOriginalTableName()}{shardingConfig.TailPrefix}{tail} will created");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace ShardingCore.Test50
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList1()
|
public async Task ToList_All_Test()
|
||||||
{
|
{
|
||||||
var mods=await _virtualDbContext.Set<SysUserMod>().ToShardingListAsync();
|
var mods=await _virtualDbContext.Set<SysUserMod>().ToShardingListAsync();
|
||||||
Assert.Equal(100,mods.Count);
|
Assert.Equal(100,mods.Count);
|
||||||
|
@ -31,7 +31,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.Equal(1000,ranges.Count);
|
Assert.Equal(1000,ranges.Count);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList1_OrderBy()
|
public async Task ToList1_OrderBy_Test()
|
||||||
{
|
{
|
||||||
var modascs=await _virtualDbContext.Set<SysUserMod>().OrderBy(o=>o.Age).ToShardingListAsync();
|
var modascs=await _virtualDbContext.Set<SysUserMod>().OrderBy(o=>o.Age).ToShardingListAsync();
|
||||||
Assert.Equal(100,modascs.Count);
|
Assert.Equal(100,modascs.Count);
|
||||||
|
@ -41,7 +41,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.Equal(1,moddescs.Last().Age);
|
Assert.Equal(1,moddescs.Last().Age);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList2()
|
public async Task ToList_Id_In_Test()
|
||||||
{
|
{
|
||||||
var ids = new[] {"1", "2", "3", "4"};
|
var ids = new[] {"1", "2", "3", "4"};
|
||||||
var sysUserMods=await _virtualDbContext.Set<SysUserMod>().Where(o=>ids.Contains(o.Id)).ToShardingListAsync();
|
var sysUserMods=await _virtualDbContext.Set<SysUserMod>().Where(o=>ids.Contains(o.Id)).ToShardingListAsync();
|
||||||
|
@ -53,7 +53,7 @@ namespace ShardingCore.Test50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList3()
|
public async Task ToList_Id_Eq_Test()
|
||||||
{
|
{
|
||||||
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id=="3").ToShardingListAsync();
|
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id=="3").ToShardingListAsync();
|
||||||
Assert.Single(mods);
|
Assert.Single(mods);
|
||||||
|
@ -63,7 +63,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.Equal("3",ranges[0].Id);
|
Assert.Equal("3",ranges[0].Id);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList4()
|
public async Task ToList_Id_Not_Eq_Test()
|
||||||
{
|
{
|
||||||
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id!="3").ToShardingListAsync();
|
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id!="3").ToShardingListAsync();
|
||||||
Assert.Equal(99,mods.Count);
|
Assert.Equal(99,mods.Count);
|
||||||
|
@ -73,7 +73,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.DoesNotContain(ranges,o=>o.Id=="3");
|
Assert.DoesNotContain(ranges,o=>o.Id=="3");
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList5()
|
public async Task ToList_Name_Eq_Test()
|
||||||
{
|
{
|
||||||
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Name=="name_3").ToShardingListAsync();
|
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Name=="name_3").ToShardingListAsync();
|
||||||
Assert.Single(mods);
|
Assert.Single(mods);
|
||||||
|
@ -83,7 +83,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.Equal("3",ranges[0].Id);
|
Assert.Equal("3",ranges[0].Id);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList6()
|
public async Task ToList_Id_Eq_Not_In_Db_Test()
|
||||||
{
|
{
|
||||||
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id=="1001").ToShardingListAsync();
|
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id=="1001").ToShardingListAsync();
|
||||||
Assert.Empty(mods);
|
Assert.Empty(mods);
|
||||||
|
@ -91,7 +91,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.Empty(ranges);
|
Assert.Empty(ranges);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ToList7()
|
public async Task ToList_Name_Eq_Not_In_Db_Test()
|
||||||
{
|
{
|
||||||
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Name=="name_1001").ToShardingListAsync();
|
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Name=="name_1001").ToShardingListAsync();
|
||||||
Assert.Empty(mods);
|
Assert.Empty(mods);
|
||||||
|
@ -99,7 +99,7 @@ namespace ShardingCore.Test50
|
||||||
Assert.Empty(ranges);
|
Assert.Empty(ranges);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FirstOrDefault1()
|
public async Task FirstOrDefault_Order_By_Id_Test()
|
||||||
{
|
{
|
||||||
var sysUserMod=await _virtualDbContext.Set<SysUserMod>().OrderBy(o=>o.Id).ShardingFirstOrDefaultAsync();
|
var sysUserMod=await _virtualDbContext.Set<SysUserMod>().OrderBy(o=>o.Id).ShardingFirstOrDefaultAsync();
|
||||||
Assert.True(sysUserMod!=null&&sysUserMod.Id=="1");
|
Assert.True(sysUserMod!=null&&sysUserMod.Id=="1");
|
||||||
|
|
Loading…
Reference in New Issue