优化单元测试名称

This commit is contained in:
xuejmnet 2021-01-26 14:56:38 +08:00
parent b0ab0815e2
commit 9d2f4cc7e0
15 changed files with 31 additions and 41 deletions

View File

@ -28,7 +28,7 @@ namespace ShardingCore.MySql
*/
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)
throw new ArgumentNullException($"AddScfSqlServerProvider :{nameof(configure)}");

View File

@ -38,27 +38,22 @@ namespace ShardingCore.Core.VirtualRoutes.Abstractions
_logger.LogWarning($"没有找到对应的匹配需要进行多表扫描:ShardingOperator:[{shardingOperator}]");
return tail => true;
//throw new NotSupportedException(xxxx);
break;
case ShardingOperatorEnum.GreaterThan:
return tail =>int.Parse(tail) > int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
case ShardingOperatorEnum.GreaterThanOrEqual:
//yyyyMMdd
return tail =>int.Parse(tail) >= int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
break;
case ShardingOperatorEnum.LessThan:
return tail =>int.Parse(tail) < int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
case ShardingOperatorEnum.LessThanOrEqual:
//yyyyMMdd
return tail =>int.Parse(tail) <= int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
break;
case ShardingOperatorEnum.Equal:
//yyyyMMdd
return tail =>int.Parse(tail) == int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
break;
case ShardingOperatorEnum.NotEqual:
//yyyyMMdd
return tail =>int.Parse(tail) != int.Parse(shardingKey.ConvertLongToTime().ToString("yyyyMMdd"));
break;
default:
throw new ArgumentOutOfRangeException(nameof(shardingOperator), shardingOperator, null);
}

View File

@ -44,25 +44,20 @@ namespace ShardingCore.Core.VirtualRoutes.Abstractions
_logger.LogWarning($"没有找到对应的匹配需要进行多表扫描:ShardingOperator:[{shardingOperator}]");
return tail => true;
//throw new NotSupportedException(xxxx);
break;
case ShardingOperatorEnum.GreaterThan:
case ShardingOperatorEnum.GreaterThanOrEqual:
//yyyyMMdd
return tail =>String.Compare(tail, GetWeekTableTail(shardingKey), StringComparison.Ordinal) >= 0;
break;
case ShardingOperatorEnum.LessThan:
case ShardingOperatorEnum.LessThanOrEqual:
//yyyyMMdd
return tail =>String.Compare(tail, GetWeekTableTail(shardingKey), StringComparison.Ordinal) <= 0;
break;
case ShardingOperatorEnum.Equal:
//yyyyMMdd
return tail =>tail == GetWeekTableTail(shardingKey);
break;
case ShardingOperatorEnum.NotEqual:
//yyyyMMdd
return tail =>tail != GetWeekTableTail(shardingKey);
break;
default:
throw new ArgumentOutOfRangeException(nameof(shardingOperator), shardingOperator, null);
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -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)
{
}
}

View File

@ -85,7 +85,7 @@ namespace ShardingCore
{
_tableCreator.CreateTable(virtualTable.EntityType, tail);
}
catch (Exception e)
catch (Exception)
{
_logger.LogWarning($"table :{virtualTable.GetOriginalTableName()}{shardingConfig.TailPrefix}{tail} will created");
}

View File

@ -23,7 +23,7 @@ namespace ShardingCore.Test50
}
[Fact]
public async Task ToList1()
public async Task ToList_All_Test()
{
var mods=await _virtualDbContext.Set<SysUserMod>().ToShardingListAsync();
Assert.Equal(100,mods.Count);
@ -31,7 +31,7 @@ namespace ShardingCore.Test50
Assert.Equal(1000,ranges.Count);
}
[Fact]
public async Task ToList1_OrderBy()
public async Task ToList1_OrderBy_Test()
{
var modascs=await _virtualDbContext.Set<SysUserMod>().OrderBy(o=>o.Age).ToShardingListAsync();
Assert.Equal(100,modascs.Count);
@ -41,7 +41,7 @@ namespace ShardingCore.Test50
Assert.Equal(1,moddescs.Last().Age);
}
[Fact]
public async Task ToList2()
public async Task ToList_Id_In_Test()
{
var ids = new[] {"1", "2", "3", "4"};
var sysUserMods=await _virtualDbContext.Set<SysUserMod>().Where(o=>ids.Contains(o.Id)).ToShardingListAsync();
@ -53,7 +53,7 @@ namespace ShardingCore.Test50
}
}
[Fact]
public async Task ToList3()
public async Task ToList_Id_Eq_Test()
{
var mods=await _virtualDbContext.Set<SysUserMod>().Where(o=>o.Id=="3").ToShardingListAsync();
Assert.Single(mods);
@ -63,7 +63,7 @@ namespace ShardingCore.Test50
Assert.Equal("3",ranges[0].Id);
}
[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();
Assert.Equal(99,mods.Count);
@ -73,7 +73,7 @@ namespace ShardingCore.Test50
Assert.DoesNotContain(ranges,o=>o.Id=="3");
}
[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();
Assert.Single(mods);
@ -83,7 +83,7 @@ namespace ShardingCore.Test50
Assert.Equal("3",ranges[0].Id);
}
[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();
Assert.Empty(mods);
@ -91,7 +91,7 @@ namespace ShardingCore.Test50
Assert.Empty(ranges);
}
[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();
Assert.Empty(mods);
@ -99,7 +99,7 @@ namespace ShardingCore.Test50
Assert.Empty(ranges);
}
[Fact]
public async Task FirstOrDefault1()
public async Task FirstOrDefault_Order_By_Id_Test()
{
var sysUserMod=await _virtualDbContext.Set<SysUserMod>().OrderBy(o=>o.Id).ShardingFirstOrDefaultAsync();
Assert.True(sysUserMod!=null&&sysUserMod.Id=="1");