From 3bf234b382a8febc0694e987d416d071a74df977 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 22 Sep 2022 21:19:44 +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/UNavTest.cs | 120 ++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 Src/Asp.Net/SqliteTest/UnitTest/UNavTest.cs diff --git a/Src/Asp.Net/SqliteTest/SqliteTest.csproj b/Src/Asp.Net/SqliteTest/SqliteTest.csproj index 85b41a0f0..15814d5ac 100644 --- a/Src/Asp.Net/SqliteTest/SqliteTest.csproj +++ b/Src/Asp.Net/SqliteTest/SqliteTest.csproj @@ -90,6 +90,7 @@ + diff --git a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs index 0d05755e9..16d96fa09 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() { + UNavTest.Init(); UnitTestReturnPkList.Init(); UCustom01.Init(); UCustom011.Init(); diff --git a/Src/Asp.Net/SqliteTest/UnitTest/UNavTest.cs b/Src/Asp.Net/SqliteTest/UnitTest/UNavTest.cs new file mode 100644 index 000000000..1eeb2c436 --- /dev/null +++ b/Src/Asp.Net/SqliteTest/UnitTest/UNavTest.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; + +namespace OrmTest +{ + public class UNavTest + { + + public static void Init() + { + var context = NewUnitTest.Db; + // context.QueryFilter.Add(new TableFilterItem(z=>z.IsDelete==1 , true)); + context.QueryFilter.Add(new TableFilterItem(z => z.IsDelete == 11, true)); + + //建表 + if (!context.DbMaintenance.IsAnyTable("DELIVERY_DETAIL_1", false)) + { + context.CodeFirst.InitTables(); + } + //建表 + if (!context.DbMaintenance.IsAnyTable("DELIVERY_DETAIL_ITEM_1", false)) + { + context.CodeFirst.InitTables(); + } + context.Aop.DataExecuting = (oldValue, entityInfo) => + { + if (entityInfo.PropertyName == "Iden" && entityInfo.OperationType == DataFilterType.InsertByObject) + { + entityInfo.SetValue(Guid.NewGuid().ToString("N").ToUpper()); + } + if (entityInfo.PropertyName == "IsDelete" && entityInfo.OperationType == DataFilterType.InsertByObject) + { + entityInfo.SetValue(0); + } + }; + DeliveryDetail deliveryDetail = new DeliveryDetail + { + DeliveryNo = "11", + + deliveryDetailItem = new DeliveryDetailItem { FieldId = "00", FieldValue = "00" } + }; + + context.InsertNav(deliveryDetail).Include(s => s.deliveryDetailItem).ExecuteCommand(); + var items = context.Queryable().ToList(); + items.ForEach(s => s.IsDelete = 1); + context.Updateable(items).ExecuteCommand(); + var result = context.Queryable().Where(s => s.DeliveryNo == "11").Includes(dd => dd.deliveryDetailItem).First(); + if (result.deliveryDetailItem != null) + { + throw new Exception("unit error"); + } + + } + + + /// + /// + /// + [SugarTable("DELIVERY_DETAIL_1")] + public partial class DeliveryDetail : Base + { + public DeliveryDetail() + { + } + + /// + /// 送货单号 + /// + [SugarColumn(ColumnName = "DELIVERY_NO")] + public string DeliveryNo { get; set; } + + + [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToOne, nameof(Iden), nameof(DeliveryDetailItem.DeliveryDetailIden))] + public DeliveryDetailItem deliveryDetailItem { get; set; } + + } + [SugarTable("DELIVERY_DETAIL_ITEM_1")] + public partial class DeliveryDetailItem : Base + { + /// + /// 送货单明细IDEN + /// + [SugarColumn(ColumnName = "DELIVERY_DETAIL_IDEN")] + public string DeliveryDetailIden { get; set; } + + /// + /// 字段编号 + /// + [SugarColumn(ColumnName = "FIELD_ID")] + public string FieldId { get; set; } + + /// + /// 字段值 + /// + [SugarColumn(ColumnName = "FIELD_VALUE")] + public string FieldValue { get; set; } + } + + public class Base + { + /// + /// 主键 + /// + [SugarColumn(IsPrimaryKey = true, ColumnName = "IDEN", ColumnDescription = "主键", ColumnDataType = "VARCHAR(50)")] + public string Iden { get; set; } + /// + /// 是否被删除 + /// + [SugarColumn(ColumnName = "IS_DELETE", ColumnDescription = "是否被删除")] + public int IsDelete { get; set; } + } + } +} + +