mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Add unit test
This commit is contained in:
@@ -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<Manufacturer, Product, DefineManufacturerAuthentication, ManufacturerAuthentication>();
|
||||
}
|
||||
db.CodeFirst.InitTables<Manufacturer, Product,DefineManufacturerAuthentication, ManufacturerAuthentication >();
|
||||
db.Queryable<Manufacturer>()
|
||||
.Where(it => it.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication)))
|
||||
.ToList();
|
||||
db.CodeFirst.InitTables<Manufacturer, Product, DefineManufacturerAuthentication, ManufacturerAuthentication>();
|
||||
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<Manufacturer>()
|
||||
.Where(it => it.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication)))
|
||||
.ToList();
|
||||
|
||||
var list3 = db.Queryable<Manufacturer>().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<Product>()
|
||||
.Where(it => it.Manufacturer.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication)))
|
||||
.ToList();
|
||||
|
||||
var list3 = db.Queryable<Product>().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<Product>()
|
||||
.Where(it => it.Manufacturer.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication)))
|
||||
.ToList();
|
||||
|
||||
var list3 = db.Queryable<Product>().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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 商品 和供应商多对一
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user