From 798ce356a22cb7f7f439b71a1a05c2f9321a3ad1 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 2 Aug 2022 20:56:02 +0800 Subject: [PATCH] Add unit test --- .../SqlServerTest/SqlServerTest.csproj | 1 + Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 + .../SqlServerTest/UnitTest/UnitSelectN.cs | 96 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UnitSelectN.cs diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj index ee2cb352c..bf5cda9dc 100644 --- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj +++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj @@ -97,6 +97,7 @@ + diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs index cb34fba3c..04c4c0cae 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UnitSelectN.Init(); UnitOneToOneN2.Init(); UnitManyToManyUpdate.Init(); UnitManyToMay1231.Init(); diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UnitSelectN.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UnitSelectN.cs new file mode 100644 index 000000000..4b96e88ab --- /dev/null +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UnitSelectN.cs @@ -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(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.DbMaintenance.TruncateTable(); + db.Insertable(new B() { BId = 1, AId = 1, BName = "a" }).ExecuteCommand(); + var data=db.Queryable() + .LeftJoin((b, a) => b.AId == a.AId) + .LeftJoin((b, a, aa) => a.AId == aa.AId) + .LeftJoin((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() + .LeftJoin((b, a) => b.AId == a.AId) + .LeftJoin((b, a, aa) => a.AId == aa.AId) + .LeftJoin((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; } + } + } +}