Add unit test

This commit is contained in:
sunkaixuan 2023-02-12 14:59:44 +08:00
parent ea04089c38
commit 6c4a7cf073
4 changed files with 176 additions and 0 deletions

View File

@ -138,6 +138,7 @@
<Compile Include="UnitTest\UInsert3.cs" />
<Compile Include="UnitTest\UnitCustom01.cs" />
<Compile Include="UnitTest\UnitSameKeyBug.cs" />
<Compile Include="UnitTest\UnitSqlFunc.cs" />
<Compile Include="UnitTest\UnitSubToList.cs" />
<Compile Include="UnitTest\UnitSubToList001.cs" />
<Compile Include="UnitTest\UnitTestReturnPkList.cs" />

View File

@ -0,0 +1,87 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class UnitSqlFunc
{
public static void Init()
{
var db = NewUnitTest.Db;
db.DbMaintenance.TruncateTable<Order>();
db.Insertable(new Order() { Name = "a,b,c,aa,bb,cc" }).ExecuteCommand();
db.Insertable(new Order() { Name = "e,a,c" }).ExecuteCommand();
db.Insertable(new Order() { Name = "zac" }).ExecuteCommand();
db.Insertable(new Order() { Name = "ab,az,ad" }).ExecuteCommand();
NewMethod(db);
NewMethod1(db);
NewMethod2(db);
NewMethod3(db);
NewMethod4(db);
NewMethod5(db);
NewMethod6(db);
}
private static void NewMethod1(SqlSugarClient db)
{
var count = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "a")).Count();
if (count != 2)
{
throw new Exception("unit error");
}
}
private static void NewMethod(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "c")).Count();
if (count2 != 2)
{
throw new Exception("unit error");
}
}
private static void NewMethod2(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "az")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
private static void NewMethod3(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "ab")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
private static void NewMethod4(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "ad")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
private static void NewMethod5(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "z")).Count();
if (count2 != 0)
{
throw new Exception("unit error");
}
}
private static void NewMethod6(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "zac")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
}
}

View File

@ -119,6 +119,7 @@
<Compile Include="UnitTest\UCustom014.cs" />
<Compile Include="UnitTest\UCustom015.cs" />
<Compile Include="UnitTest\UCustom016.cs" />
<Compile Include="UnitTest\UnitSqlFunc.cs" />
<Compile Include="UnitTest\UnitSubToList.cs" />
<Compile Include="UnitTest\UnitTestReturnPkList.cs" />
<Compile Include="UnitTest\USave.cs" />

View File

@ -0,0 +1,87 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class UnitSqlFunc
{
public static void Init()
{
var db = NewUnitTest.Db;
db.DbMaintenance.TruncateTable<Order>();
db.Insertable(new Order() { Name = "a,b,c,aa,bb,cc" }).ExecuteCommand();
db.Insertable(new Order() { Name = "e,a,c" }).ExecuteCommand();
db.Insertable(new Order() { Name = "zac" }).ExecuteCommand();
db.Insertable(new Order() { Name = "ab,az,ad" }).ExecuteCommand();
NewMethod(db);
NewMethod1(db);
NewMethod2(db);
NewMethod3(db);
NewMethod4(db);
NewMethod5(db);
NewMethod6(db);
}
private static void NewMethod1(SqlSugarClient db)
{
var count = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "a")).Count();
if (count != 2)
{
throw new Exception("unit error");
}
}
private static void NewMethod(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "c")).Count();
if (count2 != 2)
{
throw new Exception("unit error");
}
}
private static void NewMethod2(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "az")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
private static void NewMethod3(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "ab")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
private static void NewMethod4(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "ad")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
private static void NewMethod5(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "z")).Count();
if (count2 != 0)
{
throw new Exception("unit error");
}
}
private static void NewMethod6(SqlSugarClient db)
{
var count2 = db.Queryable<Order>().Where(it => SqlFunc.SplitIn(it.Name, "zac")).Count();
if (count2 != 1)
{
throw new Exception("unit error");
}
}
}
}