mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Add unit test
This commit is contained in:
parent
57c29d0151
commit
61ac8721d2
@ -104,6 +104,7 @@
|
|||||||
<Compile Include="Models\ViewOrder.cs" />
|
<Compile Include="Models\ViewOrder.cs" />
|
||||||
<Compile Include="Config.cs" />
|
<Compile Include="Config.cs" />
|
||||||
<Compile Include="UnitTest\UInsert3.cs" />
|
<Compile Include="UnitTest\UInsert3.cs" />
|
||||||
|
<Compile Include="UnitTest\ULock.cs" />
|
||||||
<Compile Include="UnitTest\Unit001.cs" />
|
<Compile Include="UnitTest\Unit001.cs" />
|
||||||
<Compile Include="UnitTest\UnitByteArray.cs" />
|
<Compile Include="UnitTest\UnitByteArray.cs" />
|
||||||
<Compile Include="UnitTest\UnitPgSplit.cs" />
|
<Compile Include="UnitTest\UnitPgSplit.cs" />
|
||||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
ULock.Init();
|
||||||
UInsert3.Init();
|
UInsert3.Init();
|
||||||
UnitSubToList.Init();
|
UnitSubToList.Init();
|
||||||
UnitByteArray.Init();
|
UnitByteArray.Init();
|
||||||
|
67
Src/Asp.Net/PgSqlTest/UnitTest/ULock.cs
Normal file
67
Src/Asp.Net/PgSqlTest/UnitTest/ULock.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class ULock
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = NewUnitTest.Db;
|
||||||
|
db.CodeFirst.InitTables<ULockEntity>();
|
||||||
|
db.DbMaintenance.TruncateTable<ULockEntity>();
|
||||||
|
var dt= DateTime.Now;
|
||||||
|
var id=db.Insertable(new ULockEntity()
|
||||||
|
{
|
||||||
|
Name = "oldName",
|
||||||
|
Ver= dt
|
||||||
|
}).ExecuteReturnIdentity();
|
||||||
|
|
||||||
|
var data = db.Updateable(new ULockEntity()
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Ver= DateTime.Now,
|
||||||
|
Name = "newname",
|
||||||
|
|
||||||
|
}).ExecuteCommandWithOptLock();
|
||||||
|
if (data != 1) { throw new Exception("unit error"); };
|
||||||
|
var data2 = db.Updateable(new ULockEntity()
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Name = "newname2",
|
||||||
|
|
||||||
|
}).ExecuteCommandWithOptLock();
|
||||||
|
if (data2 != 0) { throw new Exception("unit error"); };
|
||||||
|
|
||||||
|
var data3 = db.Updateable(new ULockEntity()
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Name = "newname2",
|
||||||
|
|
||||||
|
})
|
||||||
|
.UpdateColumns(z=>z.Name).ExecuteCommandWithOptLock();
|
||||||
|
if (data3 != 0) { throw new Exception("unit error"); }
|
||||||
|
var ver = db.Queryable<ULockEntity>().InSingle(id);
|
||||||
|
var data4 = db.Updateable(new ULockEntity()
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Name = "newname2",
|
||||||
|
Ver = ver.Ver
|
||||||
|
})
|
||||||
|
.UpdateColumns(z => z.Name).ExecuteCommandWithOptLock();
|
||||||
|
if (data4 != 1) { throw new Exception("unit error"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ULockEntity
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true, ColumnDataType ="timestamp" )]
|
||||||
|
public DateTime Ver { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user