From f40b96c6cb74273ba38aa1c9bbf1b51a401e0c3e Mon Sep 17 00:00:00 2001
From: sunkaixuan <610262374@qq.com>
Date: Mon, 7 Aug 2023 16:05:58 +0800
Subject: [PATCH] Add unit test
---
Src/Asp.Net/SqliteTest/SqliteTest.csproj | 1 +
Src/Asp.Net/SqliteTest/UnitTest/Main.cs | 1 +
Src/Asp.Net/SqliteTest/UnitTest/USelectDTO.cs | 129 ++++++++++++++++++
3 files changed, 131 insertions(+)
create mode 100644 Src/Asp.Net/SqliteTest/UnitTest/USelectDTO.cs
diff --git a/Src/Asp.Net/SqliteTest/SqliteTest.csproj b/Src/Asp.Net/SqliteTest/SqliteTest.csproj
index 34984abd5..7a74d0b29 100644
--- a/Src/Asp.Net/SqliteTest/SqliteTest.csproj
+++ b/Src/Asp.Net/SqliteTest/SqliteTest.csproj
@@ -121,6 +121,7 @@
+
diff --git a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs
index 05e148bf7..cd65774a2 100644
--- a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs
+++ b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs
@@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
+ USelectDTO.Init();
UnitNavOneToManyDTO.Init();
Unitadfaafsd.Init();
UFilter2.Init();
diff --git a/Src/Asp.Net/SqliteTest/UnitTest/USelectDTO.cs b/Src/Asp.Net/SqliteTest/UnitTest/USelectDTO.cs
new file mode 100644
index 000000000..739524b27
--- /dev/null
+++ b/Src/Asp.Net/SqliteTest/UnitTest/USelectDTO.cs
@@ -0,0 +1,129 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Data.SqlTypes;
+using System.Linq;
+using System.Security.Principal;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace OrmTest
+{
+ internal class USelectDTO
+ {
+ public static void Init()
+ {
+ var db = NewUnitTest.Db;
+ db.CodeFirst.InitTables();
+
+ //5.1.4.86 不报错
+ //5.1.4.94 报错
+
+ var flowQuery = db.Queryable()
+ .GroupBy(s => new { s.ProductId })
+ .Select(s => new
+ {
+ s.ProductId,
+ LastOutTime = SqlFunc.AggregateMax(s.CreateTime)
+ });
+
+ var data = db.Queryable()
+ .LeftJoin(flowQuery, (s, f) => s.ProductId == f.ProductId)
+ .Where(s => s.StockQty > 0)
+ .Select((s, f) => new ProductStockMonitorDto() { }, true)
+ .ToList();
+
+ var data2 = db.Queryable()
+ .LeftJoin(flowQuery, (s, f) => s.ProductId == f.ProductId)
+ .Where(s => s.StockQty > 0)
+ .Select()
+ .ToList();
+ }
+ }
+ public class ProductStockFlow
+ {
+ [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = false)]
+ public long Id { get; set; }
+
+ public long ProductId { get; set; }
+
+ ///
+ /// 产品货号
+ ///
+ public string ProductCode { get; set; }
+
+ ///
+ /// 产品名称
+ ///
+ public string ProductName { get; set; }
+
+ ///
+ /// 发生数量
+ ///
+ [SugarColumn(Length = 18, DecimalDigits = 4)]
+ public decimal SettleQty { get; set; }
+
+ ///
+ /// 发生类型
+ ///
+ public string SettleType { get; set; }
+
+ ///
+ /// 备注
+ ///
+ [SugarColumn(IsNullable = true)]
+ public string Remark { get; set; }
+
+ public DateTime CreateTime { get; set; }
+ }
+
+ public class ProductStock
+ {
+ [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = false)]
+ public long Id { get; set; }
+
+ public long ProductId { get; set; }
+
+ ///
+ /// 产品货号
+ ///
+ public string ProductCode { get; set; }
+
+ ///
+ /// 产品名称
+ ///
+ public string ProductName { get; set; }
+
+ ///
+ /// 库存数量
+ ///
+ [SugarColumn(Length = 18, DecimalDigits = 4)]
+ public decimal StockQty { get; set; }
+ }
+
+ public class ProductStockMonitorDto
+ {
+ public long ProductId { get; set; }
+
+ ///
+ /// 产品货号
+ ///
+ public string ProductCode { get; set; }
+
+ ///
+ /// 产品名称
+ ///
+ public string ProductName { get; set; }
+
+ ///
+ /// 库存数量
+ ///
+ public decimal StockQty { get; set; }
+
+ ///
+ /// 最后出库时间
+ ///
+ public DateTime? LastOutTime { get; set; }
+ }
+}