mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add unit test
This commit is contained in:
parent
33da4bf900
commit
798ce356a2
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitSelectN.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOneN2.cs" />
|
||||
<Compile Include="UnitTest\UnitManyToManyUpdate.cs" />
|
||||
<Compile Include="UnitTest\UnitManyToMay1231.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitSelectN.Init();
|
||||
UnitOneToOneN2.Init();
|
||||
UnitManyToManyUpdate.Init();
|
||||
UnitManyToMay1231.Init();
|
||||
|
96
Src/Asp.Net/SqlServerTest/UnitTest/UnitSelectN.cs
Normal file
96
Src/Asp.Net/SqlServerTest/UnitTest/UnitSelectN.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UnitSelectN
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<A, AA, B, BB>();
|
||||
db.DbMaintenance.TruncateTable<A>();
|
||||
db.DbMaintenance.TruncateTable<AA>();
|
||||
db.DbMaintenance.TruncateTable<B>();
|
||||
db.DbMaintenance.TruncateTable<BB>();
|
||||
db.Insertable(new B() { BId = 1, AId = 1, BName = "a" }).ExecuteCommand();
|
||||
var data=db.Queryable<B>()
|
||||
.LeftJoin<A>((b, a) => b.AId == a.AId)
|
||||
.LeftJoin<AA>((b, a, aa) => a.AId == aa.AId)
|
||||
.LeftJoin<BB>((b, a, aa, bb) => bb.BId == b.BId)
|
||||
.Select((b, a, aa, bb) => new
|
||||
{
|
||||
B =new B() { BId=b.BId, BName=b.BName, AId=a.AId}
|
||||
})
|
||||
.ToList();
|
||||
if (data.First().B.BId != 1 && data.First().B.BName != "a")
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
var data2 = db.Queryable<B>()
|
||||
.LeftJoin<A>((b, a) => b.AId == a.AId)
|
||||
.LeftJoin<AA>((b, a, aa) => a.AId == aa.AId)
|
||||
.LeftJoin<BB>((b, a, aa, bb) => bb.BId == b.BId)
|
||||
.Select((b, a, aa, bb) => new
|
||||
{
|
||||
B = new { BId = b.BId, BName = b.BName, AId = a.AId }
|
||||
})
|
||||
.ToList();
|
||||
if (data2.First().B.BId != 1 && data2.First().B.BName != "a")
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
}
|
||||
[SqlSugar.SugarTable("unita1")]
|
||||
public class A
|
||||
{
|
||||
public int AId { get; set; }
|
||||
public string AName { get; set; }
|
||||
}
|
||||
[SqlSugar.SugarTable("unitb1")]
|
||||
public class B
|
||||
{
|
||||
public int AId { get; set; }
|
||||
public int BId { get; set; }
|
||||
public string BName { get; set; }
|
||||
}
|
||||
[SqlSugar.SugarTable("unitaa1")]
|
||||
public class AA
|
||||
{
|
||||
public int AId { get; set; }
|
||||
public int AAId { get; set; }
|
||||
public string AAName { get; set; }
|
||||
}
|
||||
[SqlSugar.SugarTable("unitbb1")]
|
||||
public class BB
|
||||
{
|
||||
public int BId { get; set; }
|
||||
public int BBId { get; set; }
|
||||
public string BBName { get; set; }
|
||||
}
|
||||
|
||||
public class ADTO
|
||||
{
|
||||
public int AId { get; set; }
|
||||
public int AAId { get; set; }
|
||||
public string AName { get; set; }
|
||||
public string AAName { get; set; }
|
||||
}
|
||||
|
||||
public class BDTO
|
||||
{
|
||||
public int AId { get; set; }
|
||||
public string AName { get; set; }
|
||||
public int AAId { get; set; }
|
||||
public string AAName { get; set; }
|
||||
public int BId { get; set; }
|
||||
public int BBId { get; set; }
|
||||
public string BName { get; set; }
|
||||
public string BBName { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user