From a0fd9c59df7a5a58752dd3b6b453171c41227f22 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 5 Mar 2023 20:37:49 +0800 Subject: [PATCH] Update Unit test --- .../SqliteTest/UnitTest/Models/School.cs | 30 +++++++++++ .../SqliteTest/UnitTest/UnitNavUpdatee12.cs | 53 +++++++++++++++++-- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SqliteTest/UnitTest/Models/School.cs b/Src/Asp.Net/SqliteTest/UnitTest/Models/School.cs index 76a25f42c..8f32b6ca5 100644 --- a/Src/Asp.Net/SqliteTest/UnitTest/Models/School.cs +++ b/Src/Asp.Net/SqliteTest/UnitTest/Models/School.cs @@ -21,5 +21,35 @@ namespace Test.Model [Navigate(NavigateType.OneToMany, nameof(Playground.PId))] public List Playgrounds { get; set; } + + [Navigate(NavigateType.OneToMany, nameof(OtherThingOne.PId))] + public List OtherThingOnes { get; set; } + + [Navigate(NavigateType.OneToMany, nameof(OtherThingTwo.PId))] + public List OtherThingTwos { get; set; } + } + [SugarTable("OtherThingOne")] + public class OtherThingOne + { + [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + [SugarColumn(ColumnName = "Name")] + public string Name { get; set; } + + [SugarColumn(ColumnName = "PId")] + public int? PId { get; set; } + } + [SugarTable("OtherThingTwo")] + public class OtherThingTwo + { + [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + [SugarColumn(ColumnName = "Name")] + public string Name { get; set; } + + [SugarColumn(ColumnName = "PId")] + public int? PId { get; set; } } } diff --git a/Src/Asp.Net/SqliteTest/UnitTest/UnitNavUpdatee12.cs b/Src/Asp.Net/SqliteTest/UnitTest/UnitNavUpdatee12.cs index 0f765e079..a4a1e6b49 100644 --- a/Src/Asp.Net/SqliteTest/UnitTest/UnitNavUpdatee12.cs +++ b/Src/Asp.Net/SqliteTest/UnitTest/UnitNavUpdatee12.cs @@ -15,14 +15,18 @@ namespace OrmTest { var db = NewUnitTest.Db; db.CodeFirst.InitTables(); - + db.CodeFirst.InitTables(); Demo1(db); Demo2(db); } private static void Demo1(SqlSugarClient db) { + //清空初始化数据 db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + + //插入测试数据 db.InsertNav(new Student() { Age = "11", @@ -37,25 +41,66 @@ namespace OrmTest } , Rooms=new List(){ - new Room() { Name= "学校ROOM" } } } + new Room() { Name= "学校ROOM" } + }, + OtherThingOnes=new List() + { + new OtherThingOne(){ Name="学校One" } + }, + OtherThingTwos=new List() + { + new OtherThingTwo(){ Name="学校Two" } + } + + + } + } }) .Include(s => s.Books) - // .Include(s => s.Schools) .Include(s => s.Schools).ThenInclude(sc => sc.Rooms) .Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds) + .Include(s => s.Schools).ThenInclude(sc => sc.OtherThingOnes) + .Include(s => s.Schools).ThenInclude(sc => sc.OtherThingTwos) .ExecuteCommand(); + var data = db.Queryable() .Includes(s => s.Books) .Includes(s => s.Schools, s => s.Rooms) .Includes(s => s.Schools, s => s.Playgrounds) + .Includes(s => s.Schools, s => s.OtherThingOnes) + .Includes(s => s.Schools, s => s.OtherThingTwos) .ToList(); + + data[0].Schools[0].OtherThingOnes[0].Name = "updateOne"; + if (data.Count != 1 || data.First().Schools.Count != 1 || data.First().Schools.First().Rooms.Count() != 1 || data.First().Schools.First().Playgrounds.Count() != 1) { throw new Exception("unit error"); } + + //更新数据 + db.UpdateNav(data) + .Include(s => s.Schools).ThenInclude(sc => sc.Rooms) + .Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds) + .Include(s => s.Schools).ThenInclude(sc => sc.OtherThingOnes) + .Include(s => s.Schools).ThenInclude(sc => sc.OtherThingTwos) + .Include(s => s.Books) + .ExecuteCommand(); + + var data2 = db.Queryable() + .Includes(s => s.Books) + .Includes(s => s.Schools, s => s.Rooms) + .Includes(s => s.Schools, s => s.Playgrounds) + .Includes(s => s.Schools, s => s.OtherThingOnes) + .Includes(s => s.Schools, s => s.OtherThingTwos) + .ToList(); + if (data2.Count != 1 || data2.First().Schools.Count != 1 || data2.First().Schools.First().Rooms.Count() != 1 || data2.First().Schools.First().Playgrounds.Count() != 1) + { + throw new Exception("unit error"); + } } private static void Demo2(SqlSugarClient db) { @@ -116,7 +161,7 @@ namespace OrmTest .Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds) .Include(s => s.Books) .ExecuteCommand(); - + var data2 = db.Queryable() //.Includes(s => s.Books) .Includes(s => s.Schools, s => s.Rooms)