Add unit test

This commit is contained in:
sunkaixuan 2023-05-28 20:55:20 +08:00
parent c7d2b6987f
commit 2eeeb074d3
2 changed files with 52 additions and 0 deletions

View File

@ -31,6 +31,7 @@ namespace OrmTest
} }
public static void Init() public static void Init()
{ {
SplitTest2();
UOneManyMany7.init(); UOneManyMany7.init();
UinitCustomConvert.Init(); UinitCustomConvert.Init();
UnitFilterasdfas.Init(); UnitFilterasdfas.Init();

View File

@ -92,6 +92,39 @@ namespace OrmTest
var listall1 = db.Queryable<WordTestTable>().Where(it => it.Name == "all").SplitTable(tas => tas.InTableNames(tableName2)).ToList(); var listall1 = db.Queryable<WordTestTable>().Where(it => it.Name == "all").SplitTable(tas => tas.InTableNames(tableName2)).ToList();
var listall = db.Queryable<WordTestTable>().Where(it => it.Name == "all").SplitTable(tas => tas.ContainsTableNames("_FirstA")).ToList(); var listall = db.Queryable<WordTestTable>().Where(it => it.Name == "all").SplitTable(tas => tas.ContainsTableNames("_FirstA")).ToList();
}
public static void SplitTest2()
{
var db = Db;
db.CodeFirst.InitTables<WordTestTable2>();
//使用自定义分表
// db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new WordSplitService();
db.Insertable(new WordTestTable2()
{
CreateTime = DateTime.Now,
Name = "BC"
}).SplitTable().ExecuteReturnSnowflakeId();
db.Insertable(new WordTestTable2()
{
CreateTime = DateTime.Now,
Name = "AC"
}).SplitTable().ExecuteReturnSnowflakeId();
db.Insertable(new WordTestTable2()
{
CreateTime = DateTime.Now,
Name = "ZBZ"
}).SplitTable().ExecuteReturnSnowflakeId();
//只查A表
var tableName2 = db.SplitHelper(new WordTestTable2() { Name = "A" }).GetTableNames();
db.Updateable(new WordTestTable2() { Name="A" }).SplitTable(tas => tas.InTableNames("WordTestTable_FirstZ")).ExecuteCommand();
var listall1 = db.Queryable<WordTestTable2>().Where(it => it.Name == "all").SplitTable(tas => tas.InTableNames(tableName2)).ToList();
var listall = db.Queryable<WordTestTable2>().Where(it => it.Name == "all").SplitTable(tas => tas.ContainsTableNames("_FirstA")).ToList();
} }
} }
@ -114,6 +147,24 @@ namespace OrmTest
} }
/// <summary>
/// 随便设置一个分类
/// </summary>
[SplitTable(SplitType._Custom01,typeof(WordSplitService))]
public class WordTestTable2
{
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
[SplitField] //标识一下分表字段
public string Name { get; set; }
public DateTime CreateTime { get; set; }
}
public class WordSplitService : ISplitTableService public class WordSplitService : ISplitTableService
{ {
/// <summary> /// <summary>