File tree Expand file tree Collapse file tree
src/Goodtocode.Domain.Tests/Examples Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ]
1112public 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 ]
You can’t perform that action at this time.
0 commit comments