Browse Source

Add unit test

SqlSugar5
sunkaixuan 2 years ago
parent
commit
c27df74355
  1. 1
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
  2. 1
      Src/Asp.Net/SqlServerTest/UnitTest/Main.cs
  3. 68
      Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateNav2.cs

1
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -142,6 +142,7 @@
<Compile Include="UnitTest\UDelete.cs" />
<Compile Include="UnitTest\UFastest.cs" />
<Compile Include="UnitTest\UConfig.cs" />
<Compile Include="UnitTest\UnitUpdateNav2.cs" />
<Compile Include="UnitTest\UnitUpdateNav.cs" />
<Compile Include="UnitTest\UOneManyMany5.cs" />
<Compile Include="UnitTest\UOneManyMany4.cs" />

1
Src/Asp.Net/SqlServerTest/UnitTest/Main.cs

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UnitUpdateNav2.Init();
UnitUpdateNav.Init();
UnitOneToOneN.Init();
ULock.Init();

68
Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateNav2.cs

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static OrmTest.UOneManyMany4;
namespace OrmTest
{
internal class UnitUpdateNav2
{
public static void Init()
{
var db = NewUnitTest.Db;
db.CodeFirst.InitTables<Student_004, School_004, Room_004, Desk_004, Book_004>();
db.DbMaintenance.TruncateTable<Student_004, School_004, Room_004, Desk_004, Book_004>();
var id1 = Guid.NewGuid();
var id2 = Guid.NewGuid();
var id3 = Guid.NewGuid();
var id4 = Guid.NewGuid();
db.Insertable(new Student_004() { sid = id1, Name = "北大jack", SchoolId = id1 }).ExecuteCommand();
db.Insertable(new Student_004() { sid = 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 Book_004() { StudentId = id1, Name = "数学001" }).ExecuteCommand();
db.Insertable(new Book_004() { StudentId = id2, Name = "语文002" }).ExecuteCommand();
db.Insertable(new Room_004() { roomId = id1, schoolId = id1, roomName = "北大01室" }).ExecuteCommand();
db.Insertable(new Room_004() { roomId = id2, schoolId = id1, roomName = "北大02室" }).ExecuteCommand();
db.Insertable(new Room_004() { roomId = id3, schoolId = id2, roomName = "青华03室" }).ExecuteCommand();
db.Insertable(new Room_004() { roomId = id4, schoolId = id2, roomName = "青华04室" }).ExecuteCommand();
db.Insertable(new Desk_004() { roomId = id1, deskid = id1, deskName = "北大01室_01" }).ExecuteCommand();
db.Insertable(new Desk_004() { roomId = id2, deskid = id2, deskName = "北大02室_01" }).ExecuteCommand();
db.Insertable(new Desk_004() { roomId = id3, deskid = id3, deskName = "青华03室_01" }).ExecuteCommand();
db.Insertable(new Desk_004() { roomId = id4, deskid = id4, deskName = "青华04室_01" }).ExecuteCommand();
var list = db.Queryable<Student_004>()
.Includes(x => x.school_001, x => x.rooms, x => x.desk)
.Includes(x => x.books)
.Where(x => x.school_001.rooms.Any(z => z.desk.Any())).ToList();
if (list.Count() != 2)
{
throw new Exception("unit error");
}
list.First().books = new List<Book_004>() { new Book_004() { Name="a"} };
db.UpdateNav(list)
.Include(x=>x.books).ExecuteCommand();
var list2 = db.Queryable<Student_004>()
.Includes(x => x.books).ToList();
if (!list2.First().books.Any(it=>it.Name=="a"))
{
throw new Exception("unit error");
}
if (list2.Last().books.Count == 0)
{
throw new Exception("unit error");
}
}
}
}
Loading…
Cancel
Save