From 92085efcbcbebca034e9eeaa0a0d2207f1dc4fdb Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 4 Jul 2022 07:47:07 +0800 Subject: [PATCH] Update unit test --- .../SqlServerTest/UnitTest/UOneManyMany5.cs | 69 ++++--------------- 1 file changed, 13 insertions(+), 56 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UOneManyMany5.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UOneManyMany5.cs index 11bbb2c8e..980149e3c 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UOneManyMany5.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UOneManyMany5.cs @@ -24,8 +24,8 @@ namespace OrmTest db.Insertable(new Student_004() { sid=Guid.NewGuid(), StudentId = id1, Name = "北大jack", SchoolId = id1 }).ExecuteCommand(); db.Insertable(new Student_004() { sid=Guid.NewGuid(), StudentId = id2, Name = "青华jack", SchoolId = id2 }).ExecuteCommand(); - db.Insertable(new School_004() { scid = id1, schname = "北大" }).ExecuteCommand(); - db.Insertable(new School_004() { scid = id2, schname = "青华" }).ExecuteCommand(); + db.Insertable(new School_004() { scid=Guid.NewGuid(), scid2 = id1, schname = "北大" }).ExecuteCommand(); + db.Insertable(new School_004() { scid = Guid.NewGuid(),scid2 = id2, schname = "青华" }).ExecuteCommand(); db.Insertable(new Book_004() { StudentId = id1, Name = "数学001" }).ExecuteCommand(); db.Insertable(new Book_004() { StudentId = id2, Name = "语文002" }).ExecuteCommand(); @@ -42,65 +42,17 @@ namespace OrmTest var list = db.Queryable() - .Includes(x => x.school_001, x => x.rooms, x => x.desk) + .Includes(x => x.school_001 ) .Includes(x=>x.books) - .Where(x => x.school_001.rooms.Any(z => z.desk.Any())).ToList(); + .ToList(); - if (list.Count() != 2) - { - throw new Exception("unit error"); - } - - var list2 = db.Queryable() - .Includes(x => x.school_001, x => x.rooms) - .Where(x => x.school_001.rooms.Any(z => - z.roomName == "北大01室" && - z.desk.Any())).ToList(); - - - if (list2.Count() != 1) - { - throw new Exception("unit error"); - } - - var list3 = db.Queryable() - .Includes(x => x.school_001, x => x.rooms) - .Where(x => x.school_001.rooms.Any(z => - z.roomName == "青华03室" && - z.desk.Any(c => c.deskName == "青华03室_01"))).ToList(); - - if (list3.Count != 1) - { - throw new Exception("unit error"); - } - - var list4 = db.Queryable() - .Where(x => x.school_001.rooms.Any(z => - z.roomName == "青华03室" && - z.desk.Any(c => c.deskName == "青华04室_01"))).ToList(); - - - if (list4.Count != 0) - { - throw new Exception("unit error"); - } + db.DbMaintenance.TruncateTable(); foreach (var item in list) { item.sid = Guid.Empty; item.SchoolId = Guid.Empty; item.school_001.scid = Guid.Empty; - foreach (var r in item.school_001.rooms) - { - r.roomId = Guid.Empty; - r.schoolId = Guid.Empty; - foreach (var z in r.desk) - { - z.deskid = Guid.Empty; - z.roomId = Guid.Empty; - - } - } foreach (var z in item.books) { z.bookid = Guid.Empty; @@ -108,10 +60,14 @@ namespace OrmTest } } db.InsertNav(list.First()) - .Include(x=>x.books).ExecuteCommand(); + .Include(x=>x.books) + .Include(x=>x.school_001) + .ExecuteCommand(); db.InsertNav(list.Last()) - .Include(x=>x.books).ExecuteCommand(); + .Include(x=>x.books) + .Include(x=>x.school_001) + .ExecuteCommand(); } @@ -124,7 +80,7 @@ namespace OrmTest public string Name { get; set; } public Guid SchoolId { get; set; } - [SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne,nameof(SchoolId))] + [SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne,nameof(SchoolId),nameof(School_004.scid2))] public School_004 school_001 { get; set; } [SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Book_004.StudentId),nameof(StudentId))] public List books { get; set; } @@ -145,6 +101,7 @@ namespace OrmTest { [SqlSugar.SugarColumn(IsPrimaryKey = true )] public Guid scid { get; set; } + public Guid scid2 { get; set; } public string schname { get; set; } [SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(Room_004.schoolId))] public List rooms { get; set; }