From 7282b2581a040e076eee81f49eba59f50f77e0a7 Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Wed, 13 Apr 2022 22:28:06 +0800
Subject: [PATCH] Add unit test
---
.../SqlServerTest/SqlServerTest.csproj | 1 +
Src/Asp.Net/SqlServerTest/UnitTest/Main.cs | 1 +
.../SqlServerTest/UnitTest/UCustom014.cs | 6 +-
.../SqlServerTest/UnitTest/UCustom015.cs | 101 ++++++++++++++++++
4 files changed, 106 insertions(+), 3 deletions(-)
create mode 100644 Src/Asp.Net/SqlServerTest/UnitTest/UCustom015.cs
diff --git a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
index 397b62108..50bc783e7 100644
--- a/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
+++ b/Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
@@ -99,6 +99,7 @@
+
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs b/Src/Asp.Net/SqlServerTest/UnitTest/Main.cs
index 245489d24..5cf97a64a 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()
{
+ UCustom015.Init();
UCustom014.Init();
UCustom013.Init();
UCustom012.Init();
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCustom014.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCustom014.cs
index 79040446f..7a8a8efba 100644
--- a/Src/Asp.Net/SqlServerTest/UnitTest/UCustom014.cs
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCustom014.cs
@@ -20,9 +20,9 @@ namespace OrmTest
});
db.CodeFirst.InitTables();
- db.DbMaintenance.TruncateTable("Country111");
- db.DbMaintenance.TruncateTable("Province111");
- db.DbMaintenance.TruncateTable("City111");
+ db.DbMaintenance.TruncateTable("Country_111");
+ db.DbMaintenance.TruncateTable("Province_111");
+ db.DbMaintenance.TruncateTable("City_111");
db.Insertable(new List()
{
new Country111(){
diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCustom015.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCustom015.cs
new file mode 100644
index 000000000..58a24614d
--- /dev/null
+++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCustom015.cs
@@ -0,0 +1,101 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OrmTest
+{
+ public class UCustom015
+ {
+
+ public static void Init()
+ {
+ var db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
+ {
+ ConnectionString = Config.ConnectionString,
+ DbType = DbType.SqlServer,
+ IsAutoCloseConnection = true
+ });
+ db.DbMaintenance.CreateDatabase();
+
+ db.CodeFirst.InitTables();
+ db.CodeFirst.InitTables();
+ db.CodeFirst.InitTables();
+ db.DbMaintenance.TruncateTable("Country_1111");
+ db.DbMaintenance.TruncateTable("Province_1111");
+ db.DbMaintenance.TruncateTable("Country111Info");
+ var c = new Country1111()
+ {
+ Id=1,
+ Name="中国",InfoId=1
+ };
+ var ps = new List(){
+ new Province1111{
+ Id=1001,
+ Name="江苏", CountryId=1
+
+ },
+ new Province1111{
+ Id=1002,
+ Name="上海", CountryId=1
+
+ },
+ new Province1111{
+ Id=1003,
+ Name="北京", CountryId=1
+
+ }
+ };
+
+ db.Insertable(c).ExecuteCommand();
+ db.Insertable(ps).ExecuteCommand();
+ db.Insertable(new Country111Info { Id=1, Name="infoa"}).ExecuteCommand();
+ db.Aop.OnLogExecuted = (sq, p) =>
+ {
+ Console.WriteLine(sq);
+ };
+
+ var list = db.Queryable()
+ .Includes(x => x.Info)
+ .ToList();
+ var list2 = db.Queryable()
+ .Includes(x => x.Provinces.OrderByDescending(x111 => x111.Id).ToList())
+ .ToList();
+ }
+
+ [SugarTable("Country_1111")]
+ public class Country1111
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey =true, ColumnName = "cid")]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public int InfoId { get; set; }
+
+ [Navigat(NavigatType.OneToOne, nameof(InfoId))]
+ public Country111Info Info { get; set; }
+
+ [Navigat(NavigatType.OneToMany,nameof(Province1111.CountryId))]
+ public List Provinces { get; set; }
+ }
+
+ public class Country111Info
+ {
+ [SqlSugar.SugarColumn(IsPrimaryKey =true,ColumnName = "infoId")]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ }
+
+ [SugarTable("Province_1111")]
+ public class Province1111
+ {
+ [SqlSugar.SugarColumn( ColumnName = "pid")]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ [SugarColumn(ColumnName = "coid")]
+ public int CountryId { get; set; }
+ }
+
+ }
+}