From 2b4a118a7a79406081770a08de00376dd5c788ec Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 4 Nov 2023 17:06:49 +0800 Subject: [PATCH] Add unit test --- .../SqlSeverTest/UnitTest/Unitadfasfa.cs | 86 +++++++++++++++++-- 1 file changed, 79 insertions(+), 7 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs index e1a5ac9fa..66736f566 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs @@ -8,20 +8,92 @@ namespace OrmTest { internal class Unitadfasfa { - public static void Init() + public static void Init() { var db = NewUnitTest.Db; - var list=new string[] {"a","b" }; + var list = new string[] { "中文名称2", "中文名称4" }; //如何存在删掉重新建新表 - if (db.DbMaintenance.IsAnyTable("Product", false)) + if (db.DbMaintenance.IsAnyTable("Product", false)) { db.DbMaintenance.DropTable(); } - db.CodeFirst.InitTables(); - db.Queryable() - .Where(it => it.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) - .ToList(); + db.CodeFirst.InitTables(); + db.Ado.ExecuteCommand(@"INSERT INTO [dbo].[Product] ([Id], [ManufacturerId]) VALUES (1714179162048172032, 60732); +INSERT INTO [dbo].[Product] ([Id], [ManufacturerId]) VALUES (1714179421117747200, 60731); +INSERT INTO [dbo].[Product] ([Id], [ManufacturerId]) VALUES (1715183013903601664, 60732); +INSERT INTO [dbo].[Product] ([Id], [ManufacturerId]) VALUES (1716346588932214784, 60733); +INSERT INTO [dbo].[Product] ([Id], [ManufacturerId]) VALUES (1716598093790711808, 60731); +INSERT INTO [dbo].[Product] ([Id], [ManufacturerId]) VALUES (1719258452808830976, 60732); +INSERT INTO [dbo].[Manufacturer] ([Id], [Name]) VALUES (60731, 60732); +INSERT INTO [dbo].[Manufacturer] ([Id], [Name]) VALUES (60732, 60732); +INSERT INTO [dbo].[Manufacturer] ([Id], [Name]) VALUES (60733, 60733); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719001582437273600, 60731, 1708202032495726592); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719003887857438720, 60731, 1708202076162625536); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719003937211813888, 60732, 1708202076162625536); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719006394939740160, 60732, 1708504951212347392); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719009872995028992, 60732, 1708546354562863104); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719019162610831360, 60733, 1708202032495726592); +INSERT INTO [dbo].[ManufacturerAuthentication] ([Id], [ManufacturerId],[AuthenticationId]) VALUES (1719019162648580096, 60733, 1708546354562867777); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708202032495726592, N'中文名称1'); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708202076162625536, N'中文名称2'); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708504951212347392, N'中文名称3'); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708546354562863104, N'中文名称4'); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708546354562866666, N'中文名称5'); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708546354562867777, N'中文名称7'); +INSERT INTO [dbo].[DefineManufacturerAuthentication] ([Id], [CnAuthentication]) VALUES (1708747701719535616, N'中文名称8'); +"); + Test1(db, list); + Test2(db, list); + Test3(db, list); } + + private static void Test1(SqlSugarClient db, string[] list) + { + var list2 = db.Queryable() + .Where(it => it.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + + var list3 = db.Queryable().Includes(x =>x.Authentications, it => it.Authentication) + .ToList(); + + var list4 = list3.Where(it => it.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + + if (list2.Count != list4.Count) + { + throw new Exception("unit error"); + } + } + private static void Test2(SqlSugarClient db, string[] list) + { + var list2 = db.Queryable() + .Where(it => it.Manufacturer.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + + var list3 = db.Queryable().Includes(x => x.Manufacturer, it => it.Authentications, it => it.Authentication) + .ToList(); + + var list4 = list3.Where(it => it.Manufacturer.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + + if (list2.Count != list4.Count) + { + throw new Exception("unit error"); + } + } + private static void Test3(SqlSugarClient db, string[] list) + { + var list2 = db.Queryable() + .Where(it => it.Manufacturer.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + + var list3 = db.Queryable().Includes(x => x.Manufacturer, it => it.Authentications, it => it.Authentication) + .ToList(); + + var list4 = list3.Where(it => it.Manufacturer.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + } + /// /// 商品 和供应商多对一 ///