mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Add unit test
This commit is contained in:
parent
45c49fbcd6
commit
c7ecc4a5ef
@ -35,6 +35,10 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\..\..\Demo\DmTest\DmTest\References\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard1.1\System.Buffers.dll</HintPath>
|
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard1.1\System.Buffers.dll</HintPath>
|
||||||
@ -99,6 +103,7 @@
|
|||||||
<Compile Include="Models\Tree.cs" />
|
<Compile Include="Models\Tree.cs" />
|
||||||
<Compile Include="Models\ViewOrder.cs" />
|
<Compile Include="Models\ViewOrder.cs" />
|
||||||
<Compile Include="Config.cs" />
|
<Compile Include="Config.cs" />
|
||||||
|
<Compile Include="UnitTest\UJsonFunc.cs" />
|
||||||
<Compile Include="UnitTest\UCustom013.cs" />
|
<Compile Include="UnitTest\UCustom013.cs" />
|
||||||
<Compile Include="UnitTest\UCustom07.cs" />
|
<Compile Include="UnitTest\UCustom07.cs" />
|
||||||
<Compile Include="UnitTest\UCustom08.cs" />
|
<Compile Include="UnitTest\UCustom08.cs" />
|
||||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
UJsonFunc.Init();
|
||||||
UnitTestReturnPkList.Init();
|
UnitTestReturnPkList.Init();
|
||||||
UCustom07.Init();
|
UCustom07.Init();
|
||||||
UCustom016.Init();
|
UCustom016.Init();
|
||||||
|
79
Src/Asp.Net/PgSqlTest/UnitTest/UJsonFunc.cs
Normal file
79
Src/Asp.Net/PgSqlTest/UnitTest/UJsonFunc.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class UJsonFunc
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = NewUnitTest.Db;
|
||||||
|
db.CodeFirst.InitTables<UnitJsonTest22>();
|
||||||
|
db.DbMaintenance.TruncateTable<UnitJsonTest22>();
|
||||||
|
|
||||||
|
|
||||||
|
db.Insertable(new UnitJsonTest22() { A = JObject.Parse(db.Utilities.SerializeObject(new { Id = 1 }))}).ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
db.Insertable(new UnitJsonTest22() { A = JObject.Parse(db.Utilities.SerializeObject(new { Id = 2,hh=new string[] { "1","2"},zz=new { b=111} })) }).ExecuteCommand();
|
||||||
|
|
||||||
|
db.Insertable(new UnitJsonTest22() { A = JObject.Parse(db.Utilities.SerializeObject(new { Id = 2, zz = new { b = 222 } })) }).ExecuteCommand();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var list = db.Queryable<UnitJsonTest22>()
|
||||||
|
.Where(x =>Convert.ToInt32(SqlFunc.JsonField(x.A,"zz","b")) == 111)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (list.Count != 1) { throw new Exception("unit error"); }
|
||||||
|
|
||||||
|
var list2 = db.Queryable<UnitJsonTest22>()
|
||||||
|
.Where(x => Convert.ToInt32(SqlFunc.JsonField(x.A, "Id")) == 1)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (list2.Count != 1) { throw new Exception("unit error"); }
|
||||||
|
|
||||||
|
|
||||||
|
var list3 = db.Queryable<UnitJsonTest22>().Select(it=>new { x = SqlFunc.JsonParse(it.A)}).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
db.CodeFirst.InitTables<UnitJsonTest221>();
|
||||||
|
db.Insertable(new UnitJsonTest221() { A = JArray.Parse("[1,2]") }).ExecuteCommand();
|
||||||
|
var list4 = db.Queryable<UnitJsonTest221>().Select(it => new { x = SqlFunc.JsonArrayLength(it.A) }).ToList();
|
||||||
|
|
||||||
|
if (list4.First().x != 2) { throw new Exception("unit error"); }
|
||||||
|
|
||||||
|
var list5 = db.Queryable<UnitJsonTest22>().Select(it => new { x = SqlFunc.JsonContainsFieldName(it.A,"id") }).ToList();
|
||||||
|
if (list5.First().x != false) { throw new Exception("unit error"); }
|
||||||
|
|
||||||
|
var list6 = db.Queryable<UnitJsonTest22>().Select(it => new { x = SqlFunc.JsonContainsFieldName(it.A, "Id") }).ToList();
|
||||||
|
if (list6.First().x != true) { throw new Exception("unit error"); }
|
||||||
|
|
||||||
|
|
||||||
|
var list7 = db.Queryable<UnitJsonTest22>()
|
||||||
|
.Where(x => SqlFunc.JsonField(x.A, "hh","{int:1}") == "2")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var list8= db.Queryable<UnitJsonTest22>()
|
||||||
|
.Where(x => SqlFunc.JsonLike(x.A,"hh"))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
db.DbMaintenance.DropTable<UnitJsonTest22>();
|
||||||
|
}
|
||||||
|
public class UnitJsonTest22
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsJson =true)]
|
||||||
|
public JObject A { get; set; }
|
||||||
|
}
|
||||||
|
public class UnitJsonTest221
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsJson = true)]
|
||||||
|
public JArray A { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user