mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 04:45:54 +08:00
Update unit test
This commit is contained in:
parent
8d140b93e0
commit
67bfc2697b
@ -120,6 +120,7 @@
|
||||
<Compile Include="Models\Unit\Custom1\PurchaseDetailModel.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="Demo\DemoJ_Report.cs" />
|
||||
<Compile Include="UnitTest\UinitCustomConvert.cs" />
|
||||
<Compile Include="UnitTest\Unitadsfasf1.cs" />
|
||||
<Compile Include="UnitTest\CrossDatabase02.cs" />
|
||||
<Compile Include="UnitTest\Models\BilPayment.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UinitCustomConvert.Init();
|
||||
Unitadsfasf1.Init();
|
||||
UnitSubToList001.Init();
|
||||
UInsert3.Init();
|
||||
|
94
Src/Asp.Net/MySqlTest/UnitTest/UinitCustomConvert.cs
Normal file
94
Src/Asp.Net/MySqlTest/UnitTest/UinitCustomConvert.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
using SqlSugar.Extensions;
|
||||
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.DbMaintenance.CreateDatabase();
|
||||
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();
|
||||
if (data.First().EnumValue != null)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data.First().DcValue["1"].ObjToInt() != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
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();
|
||||
var data2 = db.Queryable<Uinitadfa22122>().Where(it => SqlSugar.DbType.MySql == it.EnumValue).ToList();
|
||||
if (data.First().EnumValue != SqlSugar.DbType.MySql)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data.First().DcValue["1"].ObjToInt() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
var dt = db.Queryable<Uinitadfa22122>().ToDataTable();
|
||||
if (dt.Columns["EnumValue"].DataType != typeof(string))
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data2.First().EnumValue != data.First().EnumValue)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Uinitadfa22122
|
||||
{
|
||||
|
||||
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(1000)", 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 class DictionaryConvert : ISugarDataConverter
|
||||
{
|
||||
public SugarParameter ParameterConverter<T>(object value, int i)
|
||||
{
|
||||
var name = "@myp" + i;
|
||||
var str = new SerializeService().SerializeObject(value);
|
||||
return new SugarParameter(name, str);
|
||||
}
|
||||
|
||||
public T QueryConverter<T>(IDataRecord dr, int i)
|
||||
{
|
||||
var str = dr.GetValue(i) + "";
|
||||
return new SerializeService().DeserializeObject<T>(str);
|
||||
}
|
||||
}
|
||||
}
|
@ -103,6 +103,7 @@
|
||||
<Compile Include="Models\Tree.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="UnitTest\UinitCustomConvert.cs" />
|
||||
<Compile Include="UnitTest\UInsert3.cs" />
|
||||
<Compile Include="UnitTest\ULock.cs" />
|
||||
<Compile Include="UnitTest\Unit001.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UinitCustomConvert.Init();
|
||||
ULock.Init();
|
||||
UInsert3.Init();
|
||||
UnitSubToList.Init();
|
||||
|
94
Src/Asp.Net/PgSqlTest/UnitTest/UinitCustomConvert.cs
Normal file
94
Src/Asp.Net/PgSqlTest/UnitTest/UinitCustomConvert.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
using SqlSugar.Extensions;
|
||||
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.DbMaintenance.CreateDatabase();
|
||||
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();
|
||||
if (data.First().EnumValue != null)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data.First().DcValue["1"].ObjToInt() != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
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();
|
||||
var data2 = db.Queryable<Uinitadfa22122>().Where(it => SqlSugar.DbType.MySql == it.EnumValue).ToList();
|
||||
if (data.First().EnumValue != SqlSugar.DbType.MySql)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data.First().DcValue["1"].ObjToInt() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
var dt = db.Queryable<Uinitadfa22122>().ToDataTable();
|
||||
if (dt.Columns["EnumValue"].DataType != typeof(string))
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data2.First().EnumValue != data.First().EnumValue)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Uinitadfa22122
|
||||
{
|
||||
|
||||
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(1000)", 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 class DictionaryConvert : ISugarDataConverter
|
||||
{
|
||||
public SugarParameter ParameterConverter<T>(object value, int i)
|
||||
{
|
||||
var name = "@myp" + i;
|
||||
var str = new SerializeService().SerializeObject(value);
|
||||
return new SugarParameter(name, str);
|
||||
}
|
||||
|
||||
public T QueryConverter<T>(IDataRecord dr, int i)
|
||||
{
|
||||
var str = dr.GetValue(i) + "";
|
||||
return new SerializeService().DeserializeObject<T>(str);
|
||||
}
|
||||
}
|
||||
}
|
@ -77,6 +77,7 @@
|
||||
<Compile Include="Models\TestTree.cs" />
|
||||
<Compile Include="Models\Tree.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UinitCustomConvert.cs" />
|
||||
<Compile Include="UnitTest\Models\Book.cs" />
|
||||
<Compile Include="UnitTest\Models\Playground.cs" />
|
||||
<Compile Include="UnitTest\Models\Room.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UinitCustomConvert.Init();
|
||||
UnitNavUpdatee12.Init();
|
||||
UnitFilterdafa.Init();
|
||||
UInsert3.Init();
|
||||
|
94
Src/Asp.Net/SqliteTest/UnitTest/UinitCustomConvert.cs
Normal file
94
Src/Asp.Net/SqliteTest/UnitTest/UinitCustomConvert.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
using SqlSugar.Extensions;
|
||||
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.DbMaintenance.CreateDatabase();
|
||||
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();
|
||||
if (data.First().EnumValue != null)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data.First().DcValue["1"].ObjToInt() != 1)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
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();
|
||||
var data2 = db.Queryable<Uinitadfa22122>().Where(it => SqlSugar.DbType.MySql == it.EnumValue).ToList();
|
||||
if (data.First().EnumValue != SqlSugar.DbType.MySql)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data.First().DcValue["1"].ObjToInt() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
var dt = db.Queryable<Uinitadfa22122>().ToDataTable();
|
||||
if (dt.Columns["EnumValue"].DataType != typeof(string))
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
if (data2.First().EnumValue != data.First().EnumValue)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Uinitadfa22122
|
||||
{
|
||||
|
||||
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[SqlSugar.SugarColumn(ColumnDataType = "varchar(1000)", 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 class DictionaryConvert : ISugarDataConverter
|
||||
{
|
||||
public SugarParameter ParameterConverter<T>(object value, int i)
|
||||
{
|
||||
var name = "@myp" + i;
|
||||
var str = new SerializeService().SerializeObject(value);
|
||||
return new SugarParameter(name, str);
|
||||
}
|
||||
|
||||
public T QueryConverter<T>(IDataRecord dr, int i)
|
||||
{
|
||||
var str = dr.GetValue(i) + "";
|
||||
return new SerializeService().DeserializeObject<T>(str);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user