mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add unit test
This commit is contained in:
parent
198fdd68df
commit
4eb07269d5
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\Class1.cs" />
|
||||
<Compile Include="UnitTest\UnitSubToList.cs" />
|
||||
<Compile Include="UnitTest\Models\EntityBase.cs" />
|
||||
<Compile Include="UnitTest\UnitByteArray.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
USelectTest.Init();
|
||||
UnitSubToList.Init();
|
||||
UnitByteArray.Init();
|
||||
UnitInsertNavOneToOne.Init();
|
||||
|
64
Src/Asp.Net/SqlServerTest/UnitTest/USelectTest.cs
Normal file
64
Src/Asp.Net/SqlServerTest/UnitTest/USelectTest.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using SqlSugar;
|
||||
using System.Linq;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class USelectTest
|
||||
{
|
||||
public class SelectMenuDomain
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public int Pid { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
public class SelectMenuResponse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Pid { get; set; }
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 父类名称
|
||||
/// </summary>
|
||||
public string PName { get; set; }
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
// db.Aop.OnLogExecuting = null;
|
||||
|
||||
db.CodeFirst.InitTables<SelectMenuDomain>();
|
||||
db.DbMaintenance.DropTable<SelectMenuDomain>();
|
||||
db.CodeFirst.InitTables<SelectMenuDomain>();
|
||||
|
||||
db.Insertable(new SelectMenuDomain() { Id = 1, Name = "顶级菜单" }).ExecuteCommand();
|
||||
db.Insertable(new SelectMenuDomain() { Id = 2, Pid = 1, Name = "子集菜单" }).ExecuteCommand();
|
||||
|
||||
TestAA(db);
|
||||
|
||||
}
|
||||
private static void TestAA(SqlSugarClient db)
|
||||
{
|
||||
var test11 = db.Queryable<SelectMenuDomain>().ToList();
|
||||
var test1 = db.Queryable<SelectMenuDomain>()
|
||||
.Select(a => new SelectMenuResponse()
|
||||
{
|
||||
PName = SqlFunc.Subqueryable<SelectMenuDomain>().Where(d => d.Id == a.Pid).Select(d => d.Name)
|
||||
},
|
||||
true)
|
||||
.ToList();
|
||||
if (test1.Last().PName != "顶级菜单")
|
||||
{
|
||||
throw new System.Exception("unit error");
|
||||
}
|
||||
if (test1.Last().Id != 2)
|
||||
{
|
||||
throw new System.Exception("unit error");
|
||||
}
|
||||
if (test1.Last().Name!= "子集菜单")
|
||||
{
|
||||
throw new System.Exception("unit error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user