Add unit test

This commit is contained in:
sunkaixuna 2021-12-01 13:45:22 +08:00
parent 61a6ec6069
commit 4a2dda6677
4 changed files with 53 additions and 1 deletions

View File

@ -94,6 +94,7 @@
<Compile Include="Models\OrderItem.cs" /> <Compile Include="Models\OrderItem.cs" />
<Compile Include="Demo\Demo0_SqlSugarClient.cs" /> <Compile Include="Demo\Demo0_SqlSugarClient.cs" />
<Compile Include="Models\ViewOrder.cs" /> <Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\UDelete.cs" />
<Compile Include="UnitTest\UFastest.cs" /> <Compile Include="UnitTest\UFastest.cs" />
<Compile Include="UnitTest\USplit.cs" /> <Compile Include="UnitTest\USplit.cs" />
<Compile Include="UnitTest\Models\TB_AdminUser.cs" /> <Compile Include="UnitTest\Models\TB_AdminUser.cs" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
} }
public static void Init() public static void Init()
{ {
DeleteTest();
Fastest2(); Fastest2();
SplitTest(); SplitTest();
Filter(); Filter();

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static void DeleteTest()
{
Db.CodeFirst.InitTables<UnitDel12311>();
var list = new List<UnitDel12311>() {
new UnitDel12311(){
Date1=DateTime.Now,
ID=Guid.NewGuid(),Name="a"
},
new UnitDel12311(){
Date1=DateTime.Now,
ID=Guid.NewGuid(),Name="a"
}
};
var db = Db;
//db.CurrentConnectionConfig.MoreSettings = new SqlSugar.ConnMoreSettings()
//{
// DisableNvarchar=true
//};
db.Insertable(list).ExecuteCommand();
var r= db.Deleteable(list).ExecuteCommand();
if (r == 0)
{
throw new Exception("unit test delete");
}
}
public class UnitDel12311
{
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
public Guid ID { get; set; }
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public DateTime Date1 { get; set; }
public string Name { get; set; }
}
}
}

View File

@ -156,10 +156,14 @@ namespace SqlSugar
andString.AppendFormat(tempequals, primaryField.ToUpper(), entityValue); andString.AppendFormat(tempequals, primaryField.ToUpper(), entityValue);
} }
} }
else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL&& (this.Context.CurrentConnectionConfig.MoreSettings==null||this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower==true)) else if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL && (this.Context.CurrentConnectionConfig.MoreSettings == null || this.Context.CurrentConnectionConfig.MoreSettings?.PgSqlIsAutoToLower == true))
{ {
andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue)); andString.AppendFormat("\"{0}\"={1} ", primaryField.ToLower(), new PostgreSQLExpressionContext().GetValue(entityValue));
} }
else if (entityValue != null && UtilMethods.GetUnderType(entityValue.GetType()) == UtilConstants.DateType)
{
andString.AppendFormat("\"{0}\"={1} ", primaryField,$"'{entityValue.ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.fff")}'");
}
else else
{ {
andString.AppendFormat(tempequals, primaryField, entityValue); andString.AppendFormat(tempequals, primaryField, entityValue);