From 25bdb39694ae0ed8cc3f0cccb6be0912b7d08594 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 16 Dec 2022 20:14:03 +0800 Subject: [PATCH] Add unit test --- Src/Asp.NetCore2/KdbndpTest/UnitTest/Main.cs | 1 + .../KdbndpTest/UnitTest/UBulkCopy.cs | 117 ++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 Src/Asp.NetCore2/KdbndpTest/UnitTest/UBulkCopy.cs diff --git a/Src/Asp.NetCore2/KdbndpTest/UnitTest/Main.cs b/Src/Asp.NetCore2/KdbndpTest/UnitTest/Main.cs index d6172c8a9..7e18ee93a 100644 --- a/Src/Asp.NetCore2/KdbndpTest/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/KdbndpTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + Bulk(); CodeFirst(); Updateable(); Json(); diff --git a/Src/Asp.NetCore2/KdbndpTest/UnitTest/UBulkCopy.cs b/Src/Asp.NetCore2/KdbndpTest/UnitTest/UBulkCopy.cs new file mode 100644 index 000000000..8c36ce3db --- /dev/null +++ b/Src/Asp.NetCore2/KdbndpTest/UnitTest/UBulkCopy.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OrmTest +{ + public partial class NewUnitTest + { + public static void Bulk() + { + Db.CodeFirst.InitTables(); + Db.DbMaintenance.TruncateTable(); + var data1 = new UnitIdentity1() + { + Name = "a", + Id=1 + }; + var data2 = new UnitIdentity1() + { + Name = "b", + Id = 2 + }; + var data3 = new UnitIdentity1() + { + Name = "c", + Id = 3 + }; + Db.Fastest().BulkCopy(new List() { + data1 + }); + var list=Db.Queryable().ToList(); + if (list.Count != 1 || data1.Name != list.First().Name) + { + throw new Exception("unit Bulk"); + } + + Db.Fastest().BulkCopy(new List() { + data2, + data3 + }); + list = Db.Queryable().ToList(); + if (list.Count != 3 || !list.Any(it=>it.Name=="c")) + { + throw new Exception("unit Bulk"); + } + Db.Fastest().BulkUpdate(new List() { + new UnitIdentity1(){ + Id=1, + Name="222" + }, + new UnitIdentity1(){ + Id=2, + Name="111" + } + }); + list = Db.Queryable().ToList(); + if (list.First(it=>it.Id==1).Name!="222") + { + throw new Exception("unit Bulk"); + } + if (list.First(it => it.Id == 2).Name != "111") + { + throw new Exception("unit Bulk"); + } + if (list.First(it => it.Id == 3).Name != "c") + { + throw new Exception("unit Bulk"); + } + Db.CodeFirst.InitTables(); + Db.DbMaintenance.TruncateTable(); + var count = Db.Fastest().AS("UnitIdentity111").BulkCopy(new List { + new UnitIdentity111111111(){ Id=1, Name="jack" } + }); + if (count == 0) + { + throw new Exception("unit Bulk"); + } + count = Db.Fastest().AS("UnitIdentity111").BulkUpdate(new List { + new UnitIdentity111111111(){ Id=1, Name="jack" } + }); + if (count == 0) + { + throw new Exception("unit Bulk"); + } + Db.CodeFirst.InitTables(); + Db.Fastest().BulkUpdate(new List { + new UnitTable001(){ Id=1, table="a" } + }); + } + } + + public class UnitTable001 + { + [SqlSugar.SugarColumn(IsPrimaryKey = true)] + public int Id { get; set; } + public string table { get; set; } + } + + public class UnitIdentity111 + { + public int Id { get; set; } + public string Name { get; set; } + } + public class UnitIdentity111111111 + { + [SqlSugar.SugarColumn(IsPrimaryKey = true)] + public int Id { get; set; } + public string Name { get; set; } + } + public class UnitIdentity1 + { + [SqlSugar.SugarColumn(IsPrimaryKey =true)] + public int Id { get; set; } + public string Name { get; set; } + } +}