Update unit test

This commit is contained in:
sunkaixuan 2023-03-04 16:41:14 +08:00
parent 8d140b93e0
commit 67bfc2697b
9 changed files with 288 additions and 0 deletions

View File

@ -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" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UinitCustomConvert.Init();
Unitadsfasf1.Init();
UnitSubToList001.Init();
UInsert3.Init();

View 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);
}
}
}

View File

@ -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" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UinitCustomConvert.Init();
ULock.Init();
UInsert3.Init();
UnitSubToList.Init();

View 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);
}
}
}

View File

@ -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" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UinitCustomConvert.Init();
UnitNavUpdatee12.Init();
UnitFilterdafa.Init();
UInsert3.Init();

View 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);
}
}
}