From e6e898af6e4332f83a5d585bb98bd85331532c48 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sun, 21 Nov 2021 12:39:43 +0800 Subject: [PATCH] Add unit test --- .../SqlSeverTest/PgSqlTest/UnitTest/Main.cs | 1 + .../PgSqlTest/UnitTest/UBulkCopy.cs | 78 +++++++++++++++++++ .../PgSqlTest/UnitTest/UThread.cs | 2 +- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UBulkCopy.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/Main.cs b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/Main.cs index 269bae0f5..62f2cc4cd 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + Bulk(); CodeFirst(); Updateable(); Json(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UBulkCopy.cs b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UBulkCopy.cs new file mode 100644 index 000000000..c59a41f19 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UBulkCopy.cs @@ -0,0 +1,78 @@ +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"); + } + } + } + public class UnitIdentity1 + { + [SqlSugar.SugarColumn(IsPrimaryKey =true)] + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UThread.cs b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UThread.cs index 7b48d3a09..eeb29f08b 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UThread.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/PgSqlTest/UnitTest/UThread.cs @@ -41,7 +41,7 @@ namespace OrmTest } } }); - public static SqlSugarClient singleDb = new SqlSugarClient(new ConnectionConfig() + public static SqlSugarScope singleDb = new SqlSugarScope(new ConnectionConfig() { DbType = DbType.PostgreSQL, ConnectionString = Config.ConnectionString,