Refactor
This commit is contained in:
@@ -10,14 +10,9 @@ namespace ColaFlow.Modules.Identity.IntegrationTests.Identity;
|
||||
/// Integration tests for basic Authentication functionality (Day 4 Regression Tests)
|
||||
/// Tests registration, login, password validation, and protected endpoints
|
||||
/// </summary>
|
||||
public class AuthenticationTests : IClassFixture<DatabaseFixture>
|
||||
public class AuthenticationTests(DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public AuthenticationTests(DatabaseFixture fixture)
|
||||
{
|
||||
_client = fixture.Client;
|
||||
}
|
||||
private readonly HttpClient _client = fixture.Client;
|
||||
|
||||
[Fact]
|
||||
public async Task RegisterTenant_WithValidData_ShouldSucceed()
|
||||
|
||||
@@ -11,14 +11,9 @@ namespace ColaFlow.Modules.Identity.IntegrationTests.Identity;
|
||||
/// Integration tests for Role-Based Access Control (RBAC) functionality (Day 5 - Phase 2)
|
||||
/// Tests role assignment, JWT claims, and role persistence across authentication flows
|
||||
/// </summary>
|
||||
public class RbacTests : IClassFixture<DatabaseFixture>
|
||||
public class RbacTests(DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public RbacTests(DatabaseFixture fixture)
|
||||
{
|
||||
_client = fixture.Client;
|
||||
}
|
||||
private readonly HttpClient _client = fixture.Client;
|
||||
|
||||
[Fact]
|
||||
public async Task RegisterTenant_ShouldAssignTenantOwnerRole()
|
||||
|
||||
@@ -9,14 +9,9 @@ namespace ColaFlow.Modules.Identity.IntegrationTests.Identity;
|
||||
/// Integration tests for Refresh Token functionality (Day 5 - Phase 1)
|
||||
/// Tests token refresh flow, token rotation, and refresh token revocation
|
||||
/// </summary>
|
||||
public class RefreshTokenTests : IClassFixture<DatabaseFixture>
|
||||
public class RefreshTokenTests(DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public RefreshTokenTests(DatabaseFixture fixture)
|
||||
{
|
||||
_client = fixture.Client;
|
||||
}
|
||||
private readonly HttpClient _client = fixture.Client;
|
||||
|
||||
[Fact]
|
||||
public async Task RegisterTenant_ShouldReturnAccessAndRefreshTokens()
|
||||
|
||||
@@ -12,14 +12,9 @@ namespace ColaFlow.Modules.Identity.IntegrationTests.Identity;
|
||||
/// Integration tests for Role Management API (Day 6)
|
||||
/// Tests role assignment, user listing, user removal, and authorization policies
|
||||
/// </summary>
|
||||
public class RoleManagementTests : IClassFixture<DatabaseFixture>
|
||||
public class RoleManagementTests(DatabaseFixture fixture) : IClassFixture<DatabaseFixture>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public RoleManagementTests(DatabaseFixture fixture)
|
||||
{
|
||||
_client = fixture.Client;
|
||||
}
|
||||
private readonly HttpClient _client = fixture.Client;
|
||||
|
||||
#region Category 1: List Users Tests (3 tests)
|
||||
|
||||
|
||||
@@ -14,16 +14,10 @@ namespace ColaFlow.Modules.Identity.IntegrationTests.Infrastructure;
|
||||
/// Custom WebApplicationFactory for ColaFlow Integration Tests
|
||||
/// Supports both In-Memory and Real PostgreSQL databases
|
||||
/// </summary>
|
||||
public class ColaFlowWebApplicationFactory : WebApplicationFactory<Program>
|
||||
public class ColaFlowWebApplicationFactory(bool useInMemoryDatabase = true, string? testDatabaseName = null)
|
||||
: WebApplicationFactory<Program>
|
||||
{
|
||||
private readonly bool _useInMemoryDatabase;
|
||||
private readonly string? _testDatabaseName;
|
||||
|
||||
public ColaFlowWebApplicationFactory(bool useInMemoryDatabase = true, string? testDatabaseName = null)
|
||||
{
|
||||
_useInMemoryDatabase = useInMemoryDatabase;
|
||||
_testDatabaseName = testDatabaseName ?? $"TestDb_{Guid.NewGuid()}";
|
||||
}
|
||||
private readonly string? _testDatabaseName = testDatabaseName ?? $"TestDb_{Guid.NewGuid()}";
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
@@ -52,7 +46,7 @@ public class ColaFlowWebApplicationFactory : WebApplicationFactory<Program>
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
// Register test databases (modules won't register PostgreSQL due to Testing environment)
|
||||
if (_useInMemoryDatabase)
|
||||
if (useInMemoryDatabase)
|
||||
{
|
||||
// Use In-Memory Database for fast, isolated tests
|
||||
// IMPORTANT: Share the same database name for cross-context data consistency
|
||||
@@ -101,7 +95,7 @@ public class ColaFlowWebApplicationFactory : WebApplicationFactory<Program>
|
||||
{
|
||||
// Initialize Identity database
|
||||
var identityDb = services.GetRequiredService<IdentityDbContext>();
|
||||
if (_useInMemoryDatabase)
|
||||
if (useInMemoryDatabase)
|
||||
{
|
||||
identityDb.Database.EnsureCreated();
|
||||
}
|
||||
@@ -112,7 +106,7 @@ public class ColaFlowWebApplicationFactory : WebApplicationFactory<Program>
|
||||
|
||||
// Initialize ProjectManagement database
|
||||
var pmDb = services.GetRequiredService<PMDbContext>();
|
||||
if (_useInMemoryDatabase)
|
||||
if (useInMemoryDatabase)
|
||||
{
|
||||
pmDb.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
@@ -7,17 +7,13 @@ namespace ColaFlow.Modules.Identity.IntegrationTests.Infrastructure;
|
||||
/// </summary>
|
||||
public class DatabaseFixture : IDisposable
|
||||
{
|
||||
public ColaFlowWebApplicationFactory Factory { get; }
|
||||
public ColaFlowWebApplicationFactory Factory { get; } = new(useInMemoryDatabase: true);
|
||||
|
||||
// Note: Client property is kept for backward compatibility but creates new instances
|
||||
// Tests should call CreateClient() for isolation to avoid shared state issues
|
||||
public HttpClient Client => CreateClient();
|
||||
|
||||
public DatabaseFixture()
|
||||
{
|
||||
// Use In-Memory Database for fast, isolated tests
|
||||
Factory = new ColaFlowWebApplicationFactory(useInMemoryDatabase: true);
|
||||
}
|
||||
// Use In-Memory Database for fast, isolated tests
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new HttpClient for each test to ensure test isolation
|
||||
|
||||
Reference in New Issue
Block a user