Skip to content

Commit 37f3065

Browse files
committed
fixed parallelization and leakage
1 parent c279072 commit 37f3065

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/Goodtocode.Domain.Tests/Examples/RowLevelSecurityExample.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Goodtocode.Domain.Tests.Examples;
88
/// Shows how to implement security-by-design using TenantId, OwnerId, and audit fields.
99
/// </summary>
1010
[TestClass]
11+
[DoNotParallelize]
1112
public class RowLevelSecurityExample
1213
{
1314
#region Domain Entity with RLS
@@ -57,14 +58,19 @@ private sealed class SecuredDbContext
5758
{
5859
private readonly Guid _currentUserId;
5960
private readonly Guid _currentTenantId;
60-
private static readonly List<Document> _allDocuments = []; // Make this static
61+
private static readonly List<Document> _allDocuments = [];
6162

6263
public SecuredDbContext(Guid currentUserId, Guid currentTenantId)
6364
{
6465
_currentUserId = currentUserId;
6566
_currentTenantId = currentTenantId;
6667
}
6768

69+
/// <summary>
70+
/// Clears all documents - used for test isolation
71+
/// </summary>
72+
public static void ClearAllDocuments() => _allDocuments.Clear();
73+
6874
/// <summary>
6975
/// Simulates EF Core query filter: WHERE TenantId == @TenantId AND DeletedOn IS NULL
7076
/// </summary>
@@ -103,6 +109,17 @@ public void Add(Document document)
103109

104110
#endregion
105111

112+
#region Test Infrastructure
113+
114+
[TestInitialize]
115+
public void TestInitialize()
116+
{
117+
// Clear shared state before each test to prevent test interference
118+
SecuredDbContext.ClearAllDocuments();
119+
}
120+
121+
#endregion
122+
106123
#region Test Scenarios
107124

108125
[TestMethod]

0 commit comments

Comments
 (0)