mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-05 03:17:41 +08:00
Add unit test
This commit is contained in:
@@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UinitCustomConvert.cs" />
|
||||
<Compile Include="UnitTest\UInsert3.cs" />
|
||||
<Compile Include="UnitTest\Unitadfa1231.cs" />
|
||||
<Compile Include="UnitTest\UnitFilterasdfas.cs" />
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UinitCustomConvert.Init();
|
||||
UnitFilterasdfas.Init();
|
||||
Unitadfa1231.Init();
|
||||
UInsert3.Init();
|
||||
|
||||
67
Src/Asp.Net/SqlServerTest/UnitTest/UinitCustomConvert.cs
Normal file
67
Src/Asp.Net/SqlServerTest/UnitTest/UinitCustomConvert.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UinitCustomConvert
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<Uinitadfa22122>();
|
||||
db.DbMaintenance.TruncateTable<Uinitadfa22122>();
|
||||
db.Insertable(new Uinitadfa22122()
|
||||
{
|
||||
DcValue = new Dictionary<string, object>() { { "1", 1 } }
|
||||
}
|
||||
).ExecuteCommand();
|
||||
var data = db.Queryable<Uinitadfa22122>().ToList();
|
||||
db.Updateable(new Uinitadfa22122()
|
||||
{
|
||||
Id = 1,
|
||||
DcValue = new Dictionary<string, object>() { { "1", 2 } },
|
||||
EnumValue=SqlSugar.DbType.MySql
|
||||
}
|
||||
).ExecuteCommand();
|
||||
|
||||
data=db.Queryable<Uinitadfa22122>().Where(it=>it.EnumValue==SqlSugar.DbType.MySql).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class Uinitadfa22122
|
||||
{
|
||||
|
||||
[SugarColumn(IsIdentity =true,IsPrimaryKey =true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(max)", SqlParameterDbType = typeof(DictionaryConvert),IsNullable =true)]
|
||||
public Dictionary<string, object> DcValue { get; set; }
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert),IsNullable =true)]
|
||||
public SqlSugar.DbType? EnumValue { get;set; }
|
||||
}
|
||||
|
||||
|
||||
public static class DictionaryConvert
|
||||
{
|
||||
public static SugarParameter ParameterConverter(object value, int i)
|
||||
{
|
||||
var name = "@myp" + i;
|
||||
var str = new SerializeService().SerializeObject(value);
|
||||
return new SugarParameter(name, str);
|
||||
}
|
||||
|
||||
public static T QueryConverter<T>(this IDataRecord dr ,int i)
|
||||
{
|
||||
var str = dr.GetValue(i) + "";
|
||||
return new SerializeService().DeserializeObject<T>(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user