mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Add unit test
This commit is contained in:
parent
e64ead6288
commit
9b5dc1e39b
@ -108,6 +108,7 @@
|
||||
<Compile Include="UnitTest\UInsert3.cs" />
|
||||
<Compile Include="UnitTest\ULock.cs" />
|
||||
<Compile Include="UnitTest\Unit001.cs" />
|
||||
<Compile Include="UnitTest\Unitadfaafsd.cs" />
|
||||
<Compile Include="UnitTest\UnitByteArray.cs" />
|
||||
<Compile Include="UnitTest\UnitPgSplit.cs" />
|
||||
<Compile Include="UnitTest\UJsonFunc.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
Unitadfaafsd.Init();
|
||||
CrossDatabase02.Init();
|
||||
UinitCustomConvert.Init();
|
||||
ULock.Init();
|
||||
|
157
Src/Asp.Net/PgSqlTest/UnitTest/Unitadfaafsd.cs
Normal file
157
Src/Asp.Net/PgSqlTest/UnitTest/Unitadfaafsd.cs
Normal file
@ -0,0 +1,157 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class Unitadfaafsd
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
SqlSugarClient _db = new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = Config.ConnectionString,
|
||||
DbType = DbType.PostgreSQL,
|
||||
IsAutoCloseConnection = true
|
||||
},
|
||||
db =>
|
||||
{
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
|
||||
};
|
||||
});
|
||||
_db.CodeFirst.InitTables<JqdsrdbEntity, JqdsrgxbEntity>();
|
||||
_db.InsertNav(new JqdsrdbEntity()
|
||||
{
|
||||
Jqdsrdbh = "a",
|
||||
Jqdsrgxbs = new List<JqdsrgxbEntity>()
|
||||
{
|
||||
new JqdsrgxbEntity(){
|
||||
Jqdsrdbh= "a",
|
||||
Id= 1,
|
||||
Sfmc= "a",
|
||||
Sf="a"
|
||||
}
|
||||
}
|
||||
}).Include(x => x.Jqdsrgxbs).ExecuteCommand();
|
||||
var items = _db.Queryable<JqdsrdbEntity>()
|
||||
.Includes(dsr => dsr.Jqdsrgxbs)
|
||||
.Select((dsr) =>
|
||||
new Resp
|
||||
{
|
||||
Sf = dsr.Jqdsrgxbs.Select(sf => sf.Sfmc),
|
||||
IsShowOperationButton = true
|
||||
},
|
||||
isAutoFill: true)
|
||||
.ToListAsync().GetAwaiter().GetResult();
|
||||
|
||||
Check(items);
|
||||
|
||||
var items2 = _db.Queryable<JqdsrdbEntity>()
|
||||
.Includes(dsr => dsr.Jqdsrgxbs)
|
||||
.LeftJoin<JqdsrdbEntity>((x,y)=>x.Jqdsrdbh==y.Jqdsrdbh)
|
||||
.Select((x,y) =>
|
||||
new Resp
|
||||
{
|
||||
Sf = x.Jqdsrgxbs.Select(sf => sf.Sfmc),
|
||||
IsShowOperationButton = true
|
||||
},
|
||||
isAutoFill: true)
|
||||
.ToListAsync().GetAwaiter().GetResult();
|
||||
|
||||
Check(items2);
|
||||
|
||||
var items3 = _db.Queryable<JqdsrdbEntity>()
|
||||
.Includes(dsr => dsr.Jqdsrgxbs)
|
||||
.LeftJoin<JqdsrdbEntity>((x, y) => x.Jqdsrdbh == y.Jqdsrdbh)
|
||||
.Select((x, y) =>
|
||||
new Resp
|
||||
{
|
||||
Sf = x.Jqdsrgxbs.Select(sf => sf.Sfmc)
|
||||
},
|
||||
isAutoFill: true)
|
||||
.ToListAsync().GetAwaiter().GetResult();
|
||||
|
||||
if (items3.First().IsShowOperationButton == false)
|
||||
{
|
||||
items3.First().IsShowOperationButton = true;
|
||||
}
|
||||
Check(items3);
|
||||
|
||||
var items4= _db.Queryable<JqdsrdbEntity>()
|
||||
.Includes(dsr => dsr.Jqdsrgxbs)
|
||||
.LeftJoin<JqdsrdbEntity>((x, y) => x.Jqdsrdbh == y.Jqdsrdbh)
|
||||
.Select((x, y) =>
|
||||
new Resp
|
||||
{
|
||||
Sf = x.Jqdsrgxbs.Select(sf => sf.Sfmc)
|
||||
},
|
||||
isAutoFill: true)
|
||||
.MergeTable()
|
||||
.ToListAsync().GetAwaiter().GetResult();
|
||||
if (items4.First().IsShowOperationButton == false)
|
||||
{
|
||||
items4.First().IsShowOperationButton = true;
|
||||
}
|
||||
Check(items4);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void Check(List<Resp> items)
|
||||
{
|
||||
if (items.First().Jqdsrdbh != "a" || items.First().IsShowOperationButton == false ||
|
||||
items.First().Sf.Count() == 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
}
|
||||
[SugarTable("jqdsrdb")]
|
||||
public class JqdsrdbEntity
|
||||
{
|
||||
|
||||
[SugarColumn(ColumnName = "jqdsrdbh", IsPrimaryKey = true)]
|
||||
public string Jqdsrdbh { get; set; }
|
||||
|
||||
[Navigate(NavigateType.OneToMany, nameof(JqdsrgxbEntity.Jqdsrdbh))]
|
||||
public List<JqdsrgxbEntity> Jqdsrgxbs { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[SugarTable("jqdsrgxb")]
|
||||
public class JqdsrgxbEntity
|
||||
{
|
||||
[SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "sf")]
|
||||
public string Sf { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "sfmc")]
|
||||
public string Sfmc { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "jqdsrdbh")]
|
||||
public string Jqdsrdbh { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class Resp
|
||||
{
|
||||
public string Jqdsrdbh { get; set; }
|
||||
public bool IsShowOperationButton { get; set; }
|
||||
|
||||
public IEnumerable<string> Sf { get; set; }
|
||||
}
|
||||
|
||||
public class JqdsrgxbModel
|
||||
{
|
||||
public string Sf { get; set; }
|
||||
|
||||
public string Sfmc { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user