public void NormalTest() { var buf = Rand.NextBytes(1024); var log = new Log2 { Category = "test", Action = "abc", Remark = buf, }; log.Insert(); Assert.True(log.ID > 0); var log2 = Log2.FindByID(log.ID); Assert.NotNull(log2); Assert.Equal(buf, log2.Remark); var buf2 = Rand.NextBytes(1024); log2.Remark = buf2; log2.Update(); var log3 = Log2.FindByID(log.ID); Assert.NotNull(log3); Assert.Equal(buf2, log3.Remark); log.Delete(); }
public void ShardTestSQLite2() { // 配置自动分表策略,一般在实体类静态构造函数中配置 var shard = new TimeShardPolicy("ID", Log2.Meta.Factory) { //Field = Log2._.ID, ConnPolicy = "{0}_{1:yyyy}", TablePolicy = "{0}_{1:yyyyMMdd}", }; Log2.Meta.ShardPolicy = shard; // 拦截Sql,仅为了断言,非业务代码 var sqls = new List <String>(); DAL.LocalFilter = s => sqls.Add(s); var time = DateTime.Now; var log = new Log2 { Action = "分表", Category = Rand.NextString(8), CreateTime = time, }; // 添删改查全部使用新表名 log.Insert(); Assert.StartsWith($"[test_{time:yyyy}] Insert Into Log2_{time:yyyyMMdd}(", sqls[^ 1]);