mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add unit test
This commit is contained in:
parent
1ff18cee18
commit
8c3a09c4c7
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitInsertNav.cs" />
|
||||
<Compile Include="UnitTest\UnitSelectN.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOneN2.cs" />
|
||||
<Compile Include="UnitTest\UnitManyToManyUpdate.cs" />
|
||||
|
@ -31,6 +31,8 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitInsertNav.Init();
|
||||
UnitInsertNav.Init();
|
||||
UnitSelectN.Init();
|
||||
UnitOneToOneN2.Init();
|
||||
UnitManyToManyUpdate.Init();
|
||||
|
123
Src/Asp.Net/SqlServerTest/UnitTest/UnitInsertNav.cs
Normal file
123
Src/Asp.Net/SqlServerTest/UnitTest/UnitInsertNav.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UnitInsertNav
|
||||
{
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
//生成 DI 容器
|
||||
|
||||
var context = NewUnitTest.Db; ;
|
||||
context.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
if (entityInfo.PropertyName == "Iden" && entityInfo.OperationType == DataFilterType.InsertByObject)
|
||||
{
|
||||
entityInfo.SetValue(Guid.NewGuid().ToString("N").ToUpper());
|
||||
}
|
||||
};
|
||||
|
||||
//建表
|
||||
if (!context.DbMaintenance.IsAnyTable("MENU_INFO_1", false))
|
||||
{
|
||||
context.CodeFirst.InitTables<MenuInfo>();
|
||||
}
|
||||
//建表
|
||||
if (!context.DbMaintenance.IsAnyTable("ACTIVITY_RULE_1", false))
|
||||
{
|
||||
context.CodeFirst.InitTables<ActivityRule>();
|
||||
}
|
||||
context.DbMaintenance.TruncateTable<MenuInfo,ActivityRule>();
|
||||
var result = context.Insertable(new ActivityRule()
|
||||
{
|
||||
MenuIden = "1",
|
||||
RuleContent = "1"
|
||||
}).ExecuteReturnEntity ();
|
||||
|
||||
MenuInfo menuInfo = new MenuInfo
|
||||
{
|
||||
MenuCode = "2",
|
||||
ActivityRules = new List<ActivityRule> { new ActivityRule() { Iden = result.Iden, RuleContent = "2" } }
|
||||
};
|
||||
Console.WriteLine("begin insert nav");
|
||||
context.InsertNav(menuInfo)
|
||||
.Include(s => s.ActivityRules)
|
||||
.ExecuteCommand ();
|
||||
|
||||
var list = context.Queryable<MenuInfo>()
|
||||
.Includes(x => x.ActivityRules)
|
||||
.ToList();
|
||||
|
||||
if (list.First().ActivityRules.Count() == 0)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///<summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("MENU_INFO_1")]
|
||||
public partial class MenuInfo
|
||||
{
|
||||
public MenuInfo()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:唯一编号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, ColumnName = "IDEN")]
|
||||
public string Iden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:菜单编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "MENU_CODE")]
|
||||
public string MenuCode { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToMany, nameof(ActivityRule.MenuIden))]
|
||||
public List<ActivityRule> ActivityRules { get; set; }
|
||||
|
||||
}
|
||||
///<summary>
|
||||
///组织信息
|
||||
///</summary>
|
||||
[SugarTable("ACTIVITY_RULE_1")]
|
||||
public partial class ActivityRule
|
||||
{
|
||||
public ActivityRule()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// uuid
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, ColumnName = "IDEN")]
|
||||
public string Iden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单IDEN
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "MENU_IDEN")]
|
||||
public string MenuIden { get; set; }
|
||||
/// <summary>
|
||||
/// uuid
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "RUlE_CONTENT")]
|
||||
public string RuleContent { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user