mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add unit test
This commit is contained in:
parent
85733a79a4
commit
2e3dd532bc
Binary file not shown.
@ -77,6 +77,11 @@
|
||||
<Compile Include="Models\TestTree.cs" />
|
||||
<Compile Include="Models\Tree.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\Models\Book.cs" />
|
||||
<Compile Include="UnitTest\Models\Playground.cs" />
|
||||
<Compile Include="UnitTest\Models\Room.cs" />
|
||||
<Compile Include="UnitTest\Models\School.cs" />
|
||||
<Compile Include="UnitTest\Models\Student.cs" />
|
||||
<Compile Include="UnitTest\UnitFilterdafa.cs" />
|
||||
<Compile Include="UnitTest\Models\BilPayment.cs" />
|
||||
<Compile Include="UnitTest\UInsert3.cs" />
|
||||
@ -99,6 +104,7 @@
|
||||
<Compile Include="UnitTest\UInsert.cs" />
|
||||
<Compile Include="UnitTest\UJson.cs" />
|
||||
<Compile Include="UnitTest\UNavTest.cs" />
|
||||
<Compile Include="UnitTest\UnitNavUpdatee12.cs" />
|
||||
<Compile Include="UnitTest\UnitSubToList.cs" />
|
||||
<Compile Include="UnitTest\UnitTestReturnPkList.cs" />
|
||||
<Compile Include="UnitTest\Updateable.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitNavUpdatee12.Init();
|
||||
UnitFilterdafa.Init();
|
||||
UInsert3.Init();
|
||||
USaveable.Init();
|
||||
|
18
Src/Asp.Net/SqliteTest/UnitTest/Models/Book.cs
Normal file
18
Src/Asp.Net/SqliteTest/UnitTest/Models/Book.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using SqlSugar;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Test.Model
|
||||
{
|
||||
[SugarTable("BookA01")]
|
||||
public class Book
|
||||
{
|
||||
[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; }
|
||||
}
|
||||
}
|
18
Src/Asp.Net/SqliteTest/UnitTest/Models/Playground.cs
Normal file
18
Src/Asp.Net/SqliteTest/UnitTest/Models/Playground.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using SqlSugar;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Test.Model
|
||||
{
|
||||
[SugarTable("PlaygroundA01")]
|
||||
public class Playground
|
||||
{
|
||||
[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; }
|
||||
}
|
||||
}
|
18
Src/Asp.Net/SqliteTest/UnitTest/Models/Room.cs
Normal file
18
Src/Asp.Net/SqliteTest/UnitTest/Models/Room.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using SqlSugar;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Test.Model
|
||||
{
|
||||
[SugarTable("RoomA01")]
|
||||
public class Room
|
||||
{
|
||||
[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; }
|
||||
}
|
||||
}
|
25
Src/Asp.Net/SqliteTest/UnitTest/Models/School.cs
Normal file
25
Src/Asp.Net/SqliteTest/UnitTest/Models/School.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Test.Model
|
||||
{
|
||||
[SugarTable("SchoolA01")]
|
||||
public class School
|
||||
{
|
||||
[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; }
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(Room.PId))]
|
||||
public List<Room> Rooms { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(Playground.PId))]
|
||||
public List<Playground> Playgrounds { get; set; }
|
||||
}
|
||||
}
|
24
Src/Asp.Net/SqliteTest/UnitTest/Models/Student.cs
Normal file
24
Src/Asp.Net/SqliteTest/UnitTest/Models/Student.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Test.Model
|
||||
{
|
||||
[SugarTable("StudentA01")]
|
||||
public class Student
|
||||
{
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int? Id { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "Age")]
|
||||
public string Age { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(Book.PId))]
|
||||
public List<Book> Books { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(School.PId))]
|
||||
public List<School> Schools { get; set; }
|
||||
}
|
||||
}
|
99
Src/Asp.Net/SqliteTest/UnitTest/UnitNavUpdatee12.cs
Normal file
99
Src/Asp.Net/SqliteTest/UnitTest/UnitNavUpdatee12.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Test.Model;
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UnitNavUpdatee12
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<Student, School, Playground, Room, Book>();
|
||||
|
||||
Demo1(db);
|
||||
Demo2(db);
|
||||
}
|
||||
|
||||
private static void Demo1(SqlSugarClient db)
|
||||
{
|
||||
db.DbMaintenance.TruncateTable<Student, School, Playground, Room, Book>();
|
||||
db.InsertNav(new Student()
|
||||
{
|
||||
Age = "11",
|
||||
Name = "a",
|
||||
Books = new List<Book>() { new Book() { Name = "book" } },
|
||||
Schools = new List<School>() {
|
||||
new School(){
|
||||
Name="学校",
|
||||
Playgrounds=new List<Playground>()
|
||||
{
|
||||
new Playground(){ Name="学校GR"}
|
||||
|
||||
} ,
|
||||
Rooms=new List<Room>(){
|
||||
new Room() { Name= "学校ROOM" } } }
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
.Include(s => s.Books)
|
||||
// .Include(s => s.Schools)
|
||||
.Include(s => s.Schools).ThenInclude(sc => sc.Rooms)
|
||||
.Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds)
|
||||
.ExecuteCommand();
|
||||
var data = db.Queryable<Student>()
|
||||
.Includes(s => s.Books)
|
||||
.Includes(s => s.Schools, s => s.Rooms)
|
||||
.Includes(s => s.Schools, s => s.Playgrounds)
|
||||
.ToList();
|
||||
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");
|
||||
}
|
||||
}
|
||||
private static void Demo2(SqlSugarClient db)
|
||||
{
|
||||
db.DbMaintenance.TruncateTable<Student, School, Playground, Room, Book>();
|
||||
db.InsertNav(new Student()
|
||||
{
|
||||
Age = "11",
|
||||
Name = "a",
|
||||
Books = new List<Book>() { new Book() { Name = "book" } },
|
||||
Schools = new List<School>() {
|
||||
new School(){
|
||||
Name="学校",
|
||||
Playgrounds=new List<Playground>()
|
||||
{
|
||||
new Playground(){ Name="学校GR"}
|
||||
|
||||
} ,
|
||||
Rooms=new List<Room>(){
|
||||
new Room() { Name= "学校ROOM" } } }
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
// .Include(s => s.Schools)
|
||||
.Include(s => s.Schools).ThenInclude(sc => sc.Rooms)
|
||||
.Include(s => s.Schools).ThenInclude(sc => sc.Playgrounds)
|
||||
.Include(s => s.Books)
|
||||
.ExecuteCommand();
|
||||
var data = db.Queryable<Student>()
|
||||
.Includes(s => s.Books)
|
||||
.Includes(s => s.Schools, s => s.Rooms)
|
||||
.Includes(s => s.Schools, s => s.Playgrounds)
|
||||
.ToList();
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user