mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Update Unit test
This commit is contained in:
parent
a9cc067764
commit
a0fd9c59df
@ -21,5 +21,35 @@ namespace Test.Model
|
|||||||
|
|
||||||
[Navigate(NavigateType.OneToMany, nameof(Playground.PId))]
|
[Navigate(NavigateType.OneToMany, nameof(Playground.PId))]
|
||||||
public List<Playground> Playgrounds { get; set; }
|
public List<Playground> Playgrounds { get; set; }
|
||||||
|
|
||||||
|
[Navigate(NavigateType.OneToMany, nameof(OtherThingOne.PId))]
|
||||||
|
public List<OtherThingOne> OtherThingOnes { get; set; }
|
||||||
|
|
||||||
|
[Navigate(NavigateType.OneToMany, nameof(OtherThingTwo.PId))]
|
||||||
|
public List<OtherThingTwo> 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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,18 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
var db = NewUnitTest.Db;
|
var db = NewUnitTest.Db;
|
||||||
db.CodeFirst.InitTables<Student, School, Playground, Room, Book>();
|
db.CodeFirst.InitTables<Student, School, Playground, Room, Book>();
|
||||||
|
db.CodeFirst.InitTables<OtherThingTwo, OtherThingOne>();
|
||||||
Demo1(db);
|
Demo1(db);
|
||||||
Demo2(db);
|
Demo2(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Demo1(SqlSugarClient db)
|
private static void Demo1(SqlSugarClient db)
|
||||||
{
|
{
|
||||||
|
//清空初始化数据
|
||||||
db.DbMaintenance.TruncateTable<Student, School, Playground, Room, Book>();
|
db.DbMaintenance.TruncateTable<Student, School, Playground, Room, Book>();
|
||||||
|
db.DbMaintenance.TruncateTable<OtherThingOne, OtherThingTwo>();
|
||||||
|
|
||||||
|
//插入测试数据
|
||||||
db.InsertNav(new Student()
|
db.InsertNav(new Student()
|
||||||
{
|
{
|
||||||
Age = "11",
|
Age = "11",
|
||||||
@ -37,25 +41,66 @@ namespace OrmTest
|
|||||||
|
|
||||||
} ,
|
} ,
|
||||||
Rooms=new List<Room>(){
|
Rooms=new List<Room>(){
|
||||||
new Room() { Name= "学校ROOM" } } }
|
new Room() { Name= "学校ROOM" }
|
||||||
|
},
|
||||||
|
OtherThingOnes=new List<OtherThingOne>()
|
||||||
|
{
|
||||||
|
new OtherThingOne(){ Name="学校One" }
|
||||||
|
},
|
||||||
|
OtherThingTwos=new List<OtherThingTwo>()
|
||||||
|
{
|
||||||
|
new OtherThingTwo(){ Name="学校Two" }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.Include(s => s.Books)
|
.Include(s => s.Books)
|
||||||
// .Include(s => s.Schools)
|
|
||||||
.Include(s => s.Schools).ThenInclude(sc => sc.Rooms)
|
.Include(s => s.Schools).ThenInclude(sc => sc.Rooms)
|
||||||
.Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds)
|
.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();
|
.ExecuteCommand();
|
||||||
|
|
||||||
var data = db.Queryable<Student>()
|
var data = db.Queryable<Student>()
|
||||||
.Includes(s => s.Books)
|
.Includes(s => s.Books)
|
||||||
.Includes(s => s.Schools, s => s.Rooms)
|
.Includes(s => s.Schools, s => s.Rooms)
|
||||||
.Includes(s => s.Schools, s => s.Playgrounds)
|
.Includes(s => s.Schools, s => s.Playgrounds)
|
||||||
|
.Includes(s => s.Schools, s => s.OtherThingOnes)
|
||||||
|
.Includes(s => s.Schools, s => s.OtherThingTwos)
|
||||||
.ToList();
|
.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)
|
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");
|
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<Student>()
|
||||||
|
.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)
|
private static void Demo2(SqlSugarClient db)
|
||||||
{
|
{
|
||||||
@ -116,7 +161,7 @@ namespace OrmTest
|
|||||||
.Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds)
|
.Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds)
|
||||||
.Include(s => s.Books)
|
.Include(s => s.Books)
|
||||||
.ExecuteCommand();
|
.ExecuteCommand();
|
||||||
|
|
||||||
var data2 = db.Queryable<Student>()
|
var data2 = db.Queryable<Student>()
|
||||||
//.Includes(s => s.Books)
|
//.Includes(s => s.Books)
|
||||||
.Includes(s => s.Schools, s => s.Rooms)
|
.Includes(s => s.Schools, s => s.Rooms)
|
||||||
|
Loading…
Reference in New Issue
Block a user