Add unit test

This commit is contained in:
sunkaixuan 2022-12-16 12:46:17 +08:00
parent 198fdd68df
commit 4eb07269d5
3 changed files with 66 additions and 0 deletions

View File

@ -97,6 +97,7 @@
<Compile Include="Models\OrderItem.cs" /> <Compile Include="Models\OrderItem.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" /> <Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Models\ViewOrder.cs" /> <Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\Class1.cs" />
<Compile Include="UnitTest\UnitSubToList.cs" /> <Compile Include="UnitTest\UnitSubToList.cs" />
<Compile Include="UnitTest\Models\EntityBase.cs" /> <Compile Include="UnitTest\Models\EntityBase.cs" />
<Compile Include="UnitTest\UnitByteArray.cs" /> <Compile Include="UnitTest\UnitByteArray.cs" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
} }
public static void Init() public static void Init()
{ {
USelectTest.Init();
UnitSubToList.Init(); UnitSubToList.Init();
UnitByteArray.Init(); UnitByteArray.Init();
UnitInsertNavOneToOne.Init(); UnitInsertNavOneToOne.Init();

View 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");
}
}
}
}