Files
SqlSugar/Src/Asp.NetCore2/MySqlTest/UserTestCases/UnitTest/Main.cs
hsparks.codes cd212f0519 test: Add comprehensive unit tests for Navigation Properties
Added 25 comprehensive test cases for Navigation Properties:

 InsertNav Tests (Tests 1-5):
- One-to-One relationships
- One-to-Many relationships
- Many-to-Many relationships
- Deep nesting (3 levels)
- InsertNavOptions configuration

 UpdateNav Tests (Tests 6-10):
- One-to-One updates
- One-to-Many updates
- Many-to-Many updates
- Add new children
- Remove existing children

 DeleteNav Tests (Tests 11-14):
- One-to-One cascade delete
- One-to-Many cascade delete
- Many-to-Many cascade delete
- Deep cascade delete (3 levels)

 Complex Scenarios (Tests 15-18):
- Circular reference handling
- Change relationship
- Null navigation properties
- Empty collections

 Async Operations (Tests 19-21):
- InsertNavAsync
- UpdateNavAsync
- DeleteNavAsync

 Edge Cases (Tests 22-25):
- Existing children handling
- Partial updates
- Orphaned records
- Multi-level hierarchy

Test entities:
- Customer, CustomerProfile (One-to-One)
- Customer, Order, OrderItem (One-to-Many, nested)
- Student, Course, StudentCourse (Many-to-Many)

All tests include:
- Proper relationship setup
- Cascade operations
- Validation assertions
- Console output tracking
2025-11-27 05:51:51 +01:00

67 lines
1.9 KiB
C#

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest
{
public partial class NewUnitTest
{
public static SqlSugarClient Db=> new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.MySql,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (sql, p) =>
{
Console.WriteLine(sql);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
}
});
public static void RestData()
{
Db.DbMaintenance.TruncateTable<Order>();
Db.DbMaintenance.TruncateTable<OrderItem>();
}
public static void Init()
{
Unitdafasyfasfa.Init();
Unitdfaysfa.Init();
Unitsdfasfasa.Init();
Unitdfsdyss.Init();
Unitadfasfafays.Init();
Unitadfa12.Init();
Unitsdfa1231.Init();
Unitadfad1.Init();
UnitWeek.Init();
UnitTest.Init();
Unitdfasfasfa.Init();
UnitAddRemark.Init();
UnitSplitTask.Init();
UnitBulkMerge.Init();
UnitUpdateNavOneToOneFalse.Init();
UnitCreateType.Init();
UnitSubToList.Init();
UStorageable.Init();
UFastest.Init();
UNavigationProperties.Init();
Bulk();
CodeFirst();
Updateable();
Json();
Ado();
Queryable();
QueryableAsync();
Thread();
Thread2();
Thread3();
}
}
}