mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Add unit test
This commit is contained in:
parent
861ebddecb
commit
6942cddfee
@ -174,6 +174,7 @@
|
||||
<Compile Include="UnitTest\UOneManyMany3.cs" />
|
||||
<Compile Include="UnitTest\UOneManyMany2.cs" />
|
||||
<Compile Include="UnitTest\UOneManyMany.cs" />
|
||||
<Compile Include="UnitTest\USelectSinleDTO.cs" />
|
||||
<Compile Include="UnitTest\USplit.cs" />
|
||||
<Compile Include="UnitTest\Models\TB_AdminUser.cs" />
|
||||
<Compile Include="UnitTest\Models\TB_ClientConfig.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
USelectSinleDTO.Init();
|
||||
UCustom024.Init();
|
||||
UCustom24.Init();
|
||||
UCustom20.Init();
|
||||
|
79
Src/Asp.Net/SqlServerTest/UnitTest/USelectSinleDTO.cs
Normal file
79
Src/Asp.Net/SqlServerTest/UnitTest/USelectSinleDTO.cs
Normal file
@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
namespace OrmTest
|
||||
{
|
||||
public class USelectSinleDTO
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
Dto1(db);
|
||||
Dto2(db);
|
||||
Dto3(db);
|
||||
db.CodeFirst.InitTables<ClassA>();
|
||||
db.Insertable(new ClassA() { fId = 1, username = "a" }).ExecuteCommand();
|
||||
var list = db.Queryable<ClassA>().Select<ClassDTO>().ToList();
|
||||
if (list.First().fId != 1 && list.First().username != "a") throw new Exception("unit error");
|
||||
db.DbMaintenance.DropTable<ClassA>();
|
||||
}
|
||||
|
||||
private static void Dto1(SqlSugarClient db)
|
||||
{
|
||||
var sql = db.Queryable<ClassA>().Select<ClassDTO>().ToSql();
|
||||
if (sql.Key != "SELECT [f_id] AS fId ,[user_name] AS username FROM [ClassA] ")
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
private static void Dto2(SqlSugarClient db)
|
||||
{
|
||||
var sql = db.Queryable<ClassA>().Select<ClassDTO2>().ToSql();
|
||||
if (sql.Key != "SELECT [user_name] AS username FROM [ClassA] ")
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
private static void Dto3(SqlSugarClient db)
|
||||
{
|
||||
var sql = db.Queryable<ClassA>().Select<ClassDTO3>().ToSql();
|
||||
if (sql.Key != "SELECT [f_id] AS f_id ,[user_name] AS username FROM [ClassA] ")
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ClassA
|
||||
{
|
||||
[SqlSugar.SugarColumn(ColumnName = "f_id")]
|
||||
public int fId { get; set; }
|
||||
[SqlSugar.SugarColumn(ColumnName = "user_name")]
|
||||
public string username { get; set; }
|
||||
}
|
||||
public class ClassDTO3
|
||||
{
|
||||
|
||||
public int f_id { get; set; }
|
||||
|
||||
public string username { get; set; }
|
||||
}
|
||||
public class ClassDTO2
|
||||
{
|
||||
|
||||
public int fId2 { get; set; }
|
||||
|
||||
public string username { get; set; }
|
||||
}
|
||||
public class ClassDTO
|
||||
{
|
||||
|
||||
public int fId { get; set; }
|
||||
|
||||
public string username { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user