Reformat / cleanup
This commit is contained in:
@@ -1,44 +1,38 @@
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Shared;
|
||||
using ZB.MOM.WW.CBDD.Tests;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.CBDD.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for circular references and N-N relationships
|
||||
/// Validates that the source generator handles:
|
||||
/// 1. Self-referencing entities using ObjectId references (Employee → ManagerId, DirectReportIds)
|
||||
/// 2. N-N via referencing with ObjectIds (CategoryRef/ProductRef) - BEST PRACTICE
|
||||
///
|
||||
/// Note: Bidirectional embedding (Category ↔ Product with full objects) is NOT supported
|
||||
/// by the source generator and is an anti-pattern for document databases.
|
||||
/// Use referencing (ObjectIds) instead for N-N relationships.
|
||||
/// Tests for circular references and N-N relationships
|
||||
/// Validates that the source generator handles:
|
||||
/// 1. Self-referencing entities using ObjectId references (Employee → ManagerId, DirectReportIds)
|
||||
/// 2. N-N via referencing with ObjectIds (CategoryRef/ProductRef) - BEST PRACTICE
|
||||
/// Note: Bidirectional embedding (Category ↔ Product with full objects) is NOT supported
|
||||
/// by the source generator and is an anti-pattern for document databases.
|
||||
/// Use referencing (ObjectIds) instead for N-N relationships.
|
||||
/// </summary>
|
||||
public class CircularReferenceTests : IDisposable
|
||||
{
|
||||
private readonly TestDbContext _context;
|
||||
private readonly string _dbPath;
|
||||
private readonly Shared.TestDbContext _context;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CircularReferenceTests"/> class.
|
||||
/// Initializes a new instance of the <see cref="CircularReferenceTests" /> class.
|
||||
/// </summary>
|
||||
public CircularReferenceTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"cbdd_circular_test_{Guid.NewGuid()}");
|
||||
_context = new Shared.TestDbContext(_dbPath);
|
||||
_context = new TestDbContext(_dbPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes Dispose.
|
||||
/// Executes Dispose.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_context?.Dispose();
|
||||
if (Directory.Exists(_dbPath))
|
||||
{
|
||||
Directory.Delete(_dbPath, true);
|
||||
}
|
||||
if (Directory.Exists(_dbPath)) Directory.Delete(_dbPath, true);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
@@ -46,7 +40,7 @@ public class CircularReferenceTests : IDisposable
|
||||
// ========================================
|
||||
|
||||
/// <summary>
|
||||
/// Executes SelfReference_InsertAndQuery_ShouldWork.
|
||||
/// Executes SelfReference_InsertAndQuery_ShouldWork.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SelfReference_InsertAndQuery_ShouldWork()
|
||||
@@ -125,7 +119,7 @@ public class CircularReferenceTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes SelfReference_UpdateDirectReports_ShouldPersist.
|
||||
/// Executes SelfReference_UpdateDirectReports_ShouldPersist.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SelfReference_UpdateDirectReports_ShouldPersist()
|
||||
@@ -177,7 +171,7 @@ public class CircularReferenceTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes SelfReference_QueryByManagerId_ShouldWork.
|
||||
/// Executes SelfReference_QueryByManagerId_ShouldWork.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SelfReference_QueryByManagerId_ShouldWork()
|
||||
@@ -230,7 +224,7 @@ public class CircularReferenceTests : IDisposable
|
||||
// ========================================
|
||||
|
||||
/// <summary>
|
||||
/// Executes NtoNReferencing_InsertAndQuery_ShouldWork.
|
||||
/// Executes NtoNReferencing_InsertAndQuery_ShouldWork.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void NtoNReferencing_InsertAndQuery_ShouldWork()
|
||||
@@ -298,7 +292,7 @@ public class CircularReferenceTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes NtoNReferencing_UpdateRelationships_ShouldPersist.
|
||||
/// Executes NtoNReferencing_UpdateRelationships_ShouldPersist.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void NtoNReferencing_UpdateRelationships_ShouldPersist()
|
||||
@@ -358,7 +352,7 @@ public class CircularReferenceTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes NtoNReferencing_DocumentSize_RemainSmall.
|
||||
/// Executes NtoNReferencing_DocumentSize_RemainSmall.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void NtoNReferencing_DocumentSize_RemainSmall()
|
||||
@@ -390,7 +384,7 @@ public class CircularReferenceTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes NtoNReferencing_QueryByProductId_ShouldWork.
|
||||
/// Executes NtoNReferencing_QueryByProductId_ShouldWork.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void NtoNReferencing_QueryByProductId_ShouldWork()
|
||||
@@ -428,4 +422,4 @@ public class CircularReferenceTests : IDisposable
|
||||
categoriesWithProduct.ShouldContain(c => c.Name == "Category 1");
|
||||
categoriesWithProduct.ShouldContain(c => c.Name == "Category 2");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user