Update unit test

This commit is contained in:
sunkaixuan 2022-04-30 17:35:01 +08:00
parent 8a72f18798
commit dc4d08a731
3 changed files with 82 additions and 0 deletions

View File

@ -99,6 +99,7 @@
<Compile Include="Models\Tree.cs" />
<Compile Include="Models\ViewOrder.cs" />
<Compile Include="Config.cs" />
<Compile Include="UnitTest\UCustom08.cs" />
<Compile Include="UnitTest\UAopTest.cs" />
<Compile Include="UnitTest\UCustom01.cs" />
<Compile Include="UnitTest\UCustom011.cs" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UCustom08.Init();
UCustom012.Init();
UCustom014.Init();
UCustom015.Init();

View File

@ -0,0 +1,80 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public class UCustom08
{
[SugarTable("Unit00UpdateTest")]
public class UpdateTest
{
[SugarColumn(IsNullable = false, ColumnDescription = "主键", IsPrimaryKey = true)]
public Guid Id { get; set; }
[SugarColumn(IsNullable = false, ColumnDescription = "名称", ColumnDataType = "varchar(100)")]
public string TN { get; set; }
[SugarColumn(IsNullable = true, ColumnDescription = "测试")]
public long? T1 { get; set; }
}
public static void Init()
{
var db = NewUnitTest.Db;
db.Aop.OnError = (exp) =>//SQL报错
{
string sql = exp.Sql;
//exp.sql 这样可以拿到错误SQL
};
db.DbMaintenance.CreateDatabase();
db.CodeFirst.InitTables(typeof(UpdateTest));
var id = Guid.NewGuid();
db.Insertable(new UpdateTest { Id = id, TN = "asdasd" }).ExecuteCommand();
var data = db.Queryable<UpdateTest>().Where(x => x.Id == id).First();
db.Updateable<UpdateTest>()
.SetColumns(x => new UpdateTest { T1 = (int)data.T1 }).Where(x => x.Id == id).ExecuteCommand();
db.Updateable<UpdateTest>()
.SetColumns(x => new UpdateTest { T1 = data.T1 }).Where(x => x.Id == id).ExecuteCommand();
db.Updateable<UpdateTest>()
.SetColumns(x => new UpdateTest { T1 = 1 }).Where(x => x.Id == id).ExecuteCommand();
Console.ReadKey();
}
}
}