mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
Add unit test
This commit is contained in:
parent
8efa30a921
commit
712b5a3325
@ -97,6 +97,7 @@
|
|||||||
<Compile Include="Models\OrderItem.cs" />
|
<Compile Include="Models\OrderItem.cs" />
|
||||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||||
<Compile Include="Models\ViewOrder.cs" />
|
<Compile Include="Models\ViewOrder.cs" />
|
||||||
|
<Compile Include="UnitTest\UnitInsertNav2.cs" />
|
||||||
<Compile Include="UnitTest\UnitInsertNav.cs" />
|
<Compile Include="UnitTest\UnitInsertNav.cs" />
|
||||||
<Compile Include="UnitTest\UnitSelectN.cs" />
|
<Compile Include="UnitTest\UnitSelectN.cs" />
|
||||||
<Compile Include="UnitTest\UnitOneToOneN2.cs" />
|
<Compile Include="UnitTest\UnitOneToOneN2.cs" />
|
||||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
UnitInsertNav2.Init();
|
||||||
UnitInsertNav.Init();
|
UnitInsertNav.Init();
|
||||||
UnitInsertNav.Init();
|
UnitInsertNav.Init();
|
||||||
UnitSelectN.Init();
|
UnitSelectN.Init();
|
||||||
|
80
Src/Asp.Net/SqlServerTest/UnitTest/UnitInsertNav2.cs
Normal file
80
Src/Asp.Net/SqlServerTest/UnitTest/UnitInsertNav2.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class UnitInsertNav2
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = NewUnitTest.Db;
|
||||||
|
//建表
|
||||||
|
db.CodeFirst.InitTables<Country, Province, City>();
|
||||||
|
db.DbMaintenance.TruncateTable<Country, Province, City>();
|
||||||
|
|
||||||
|
//插入一级导航数据
|
||||||
|
var country = new Country
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Provinces = new List<Province> {
|
||||||
|
new Province{
|
||||||
|
Id = 1,
|
||||||
|
CountryId = 1
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
db.InsertNav(country)
|
||||||
|
.Include(it => it.Provinces)
|
||||||
|
.ExecuteCommand();
|
||||||
|
|
||||||
|
//构造二级导航数据
|
||||||
|
country.Provinces[0].Cities = new List<City>
|
||||||
|
{
|
||||||
|
new City
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
ProvinceId = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//用例代码
|
||||||
|
var result = db.InsertNav(country)
|
||||||
|
.Include(it => it.Provinces)
|
||||||
|
.ThenInclude(it => it.Cities)
|
||||||
|
.ExecuteCommand();//用例代码
|
||||||
|
if (!db.Queryable<City>().Where(it => it.Id == 1).Any())
|
||||||
|
throw new Exception("未插入二级导航数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//建类
|
||||||
|
[SugarTable("Unitaaa1Country")]
|
||||||
|
public class Country
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
[Navigate(NavigateType.OneToMany, nameof(Province.CountryId))]
|
||||||
|
public List<Province> Provinces { get; set; }
|
||||||
|
}
|
||||||
|
[SugarTable("Unitaaa1Province")]
|
||||||
|
public class Province
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long CountryId { get; set; }
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
[Navigate(NavigateType.OneToMany, nameof(City.ProvinceId))]
|
||||||
|
public List<City> Cities { get; set; }
|
||||||
|
}
|
||||||
|
[SugarTable("Unitaaa1City")]
|
||||||
|
public class City
|
||||||
|
{
|
||||||
|
[SugarColumn(IsPrimaryKey = true)]
|
||||||
|
public long Id { get; set; }
|
||||||
|
public long ProvinceId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user