From ba684e7f4b7cfdd9c0d70ed1ec44ccc905938d2c Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Tue, 26 Jul 2022 21:34:38 +0800
Subject: [PATCH] Add unit test
---
.../SqlServerTest/SqlServerTest.csproj | 1 +
Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 +
.../SqlServerTest/UnitTest/UnitOneToOneN.cs | 104 ++++++++++++++++++
3 files changed, 106 insertions(+)
create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN.cs
diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
index 0c6cbff9c..c655c2dd4 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 95b753430..0f9fa8edf 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()
{
+ UnitOneToOneN.Init();
ULock.Init();
UnitManyToMany2.Init();
UOneManyMany5.init();
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN.cs
new file mode 100644
index 000000000..f8fc3303a
--- /dev/null
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOneN.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SqlSugar;
+namespace OrmTest
+{
+ public class UnitOneToOneN
+ {
+ public static void Init()
+ {
+ var db = NewUnitTest.Db;
+
+
+ //建表
+
+ if (!db.DbMaintenance.IsAnyTable("StudentA", false))
+
+ {
+
+ db.CodeFirst.InitTables();
+
+ }
+
+ if (!db.DbMaintenance.IsAnyTable("SchoolA", false))
+
+ {
+
+ db.CodeFirst.InitTables();
+
+ }
+
+ if (!db.DbMaintenance.IsAnyTable("RoomA", false))
+
+ {
+
+ db.CodeFirst.InitTables();
+
+ }
+
+
+
+ //用例代码
+
+ var result = db.Queryable()
+
+ .Select(student => student.School.Room.RoomId)
+
+ .ToSqlString();//用例代码
+
+ if (!result.Contains("student.[SchoolNo] = SchoolA0.[SchoolNo]"))
+ {
+ throw new Exception("unit error");
+ }
+ }
+
+ public class StudentA
+
+ {
+
+ [SugarColumn(IsPrimaryKey = true)]
+
+ public int StudentId { get; set; }
+
+ public int SchoolNo { get; set; }
+
+ [Navigate(NavigateType.OneToOne, nameof(SchoolNo), nameof(SchoolA.SchoolNo))]
+
+ public SchoolA School { get; set; }
+
+
+
+ }
+
+ public class SchoolA
+
+ {
+
+ [SugarColumn(IsPrimaryKey = true)]
+
+ public int SchoolId { get; set; }
+
+ public int SchoolNo { get; set; }
+
+ public int RoomId { get; set; }
+
+ [Navigate(NavigateType.OneToOne, nameof(RoomId))]
+
+ public RoomA Room { get; set; }
+
+ }
+
+ public class RoomA
+
+ {
+
+ [SugarColumn(IsPrimaryKey = true)]
+
+ public int RoomId { get; set; }
+
+ }
+ }
+}