Add unit test

This commit is contained in:
sunkaixuan 2022-05-19 16:06:17 +08:00
parent 8d62e1419d
commit 22d5a881a0
3 changed files with 52 additions and 0 deletions

View File

@ -95,6 +95,7 @@
<Compile Include="Models\OrderItem.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\UCustom021.cs" />
<Compile Include="UnitTest\UByteArray.cs" />
<Compile Include="UnitTest\UIncludesBigData.cs" />
<Compile Include="UnitTest\UCustom020.cs" />

View File

@ -32,6 +32,7 @@ namespace OrmTest
public static void Init()
{
UByteArray.Init();
UCustom021.Inti();
UCustom020.Init();
UCustom019.Init();
UnitManyToMany.Init();

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public class UCustom021
{
public static void Inti() {
var db = NewUnitTest.Db;
db.CodeFirst.SetStringDefaultLength(20).InitTables<UnitStudent111>();
db.CodeFirst.SetStringDefaultLength(20).InitTables<UnitExam>();
var id = db.Insertable(new UnitStudent111() { Name = "小a" }).ExecuteReturnIdentity();
db.Insertable(new UnitExam
{
StudentId = id,
Number = 1,
Time = DateTime.Now
}).ExecuteCommand();
var result2 = db.Queryable<UnitStudent111>()
.Includes(e => e.Exams.Where(s => s.Id >e.Id).ToList()).ToList();
}
}
public class UnitStudent111
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
[Navigate(NavigateType.OneToMany, nameof(UnitExam.StudentId))]//BookA表中的studenId
public List<UnitExam> Exams { get; set; }
}
public class UnitExam
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int Id { get; set; }
public int StudentId { get; set; }
public int Number { get; set; }
public DateTime Time { get; set; }
}
}