Created comprehensive integration test suite for Issue Management Module with 8 test cases covering all CRUD operations, status changes, assignments, and multi-tenant isolation. Test Cases (8/8): 1. Create Issue (Story type) 2. Create Issue (Task type) 3. Create Issue (Bug type) 4. Get Issue by ID 5. List Issues 6. Change Issue Status (Kanban workflow) 7. Assign Issue to User 8. Multi-Tenant Isolation (CRITICAL security test) Bug Fix: Multi-Tenant Data Leakage - Issue: IssueRepository did not filter by TenantId, allowing cross-tenant data access - Solution: Implemented TenantContext service and added TenantId filtering to all repository queries - Security Impact: CRITICAL - prevents unauthorized access to other tenants' issues Changes: - Added ColaFlow.Modules.IssueManagement.IntegrationTests project - Added IssueManagementWebApplicationFactory for test infrastructure - Added TestAuthHelper for JWT token generation in tests - Added 8 comprehensive integration tests - Added ITenantContext and TenantContext services for tenant isolation - Updated IssueRepository to filter all queries by current tenant ID - Registered TenantContext in module DI configuration Test Status: 7/8 passed initially, 8/8 expected after multi-tenant fix Test Framework: xUnit + FluentAssertions + WebApplicationFactory Database: In-Memory (for fast, isolated tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
101 lines
3.6 KiB
C#
101 lines
3.6 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using ColaFlow.Modules.Identity.Infrastructure.Persistence;
|
|
using ColaFlow.Modules.IssueManagement.Infrastructure.Persistence;
|
|
using ColaFlow.Modules.ProjectManagement.Infrastructure.Persistence;
|
|
|
|
namespace ColaFlow.Modules.IssueManagement.IntegrationTests.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// Custom WebApplicationFactory for Issue Management Integration Tests
|
|
/// Supports In-Memory database for fast, isolated tests
|
|
/// </summary>
|
|
public class IssueManagementWebApplicationFactory : WebApplicationFactory<Program>
|
|
{
|
|
private readonly string _testDatabaseName = $"TestDb_{Guid.NewGuid()}";
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
// Set environment to Testing
|
|
builder.UseEnvironment("Testing");
|
|
|
|
// Configure test-specific settings
|
|
builder.ConfigureAppConfiguration((context, config) =>
|
|
{
|
|
// Clear existing connection strings to prevent PostgreSQL registration
|
|
config.Sources.Clear();
|
|
|
|
// Add minimal config for testing
|
|
config.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ConnectionStrings:DefaultConnection"] = "",
|
|
["ConnectionStrings:PMDatabase"] = "",
|
|
["ConnectionStrings:IMDatabase"] = "",
|
|
["Jwt:SecretKey"] = "test-secret-key-for-integration-tests-minimum-32-characters",
|
|
["Jwt:Issuer"] = "ColaFlow.Test",
|
|
["Jwt:Audience"] = "ColaFlow.Test",
|
|
["Jwt:AccessTokenExpirationMinutes"] = "15",
|
|
["Jwt:RefreshTokenExpirationDays"] = "7"
|
|
});
|
|
});
|
|
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
// Register test databases with In-Memory provider
|
|
// Use the same database name for cross-context data consistency
|
|
services.AddDbContext<IdentityDbContext>(options =>
|
|
{
|
|
options.UseInMemoryDatabase(_testDatabaseName);
|
|
options.EnableSensitiveDataLogging();
|
|
});
|
|
|
|
services.AddDbContext<PMDbContext>(options =>
|
|
{
|
|
options.UseInMemoryDatabase(_testDatabaseName);
|
|
options.EnableSensitiveDataLogging();
|
|
});
|
|
|
|
services.AddDbContext<IssueManagementDbContext>(options =>
|
|
{
|
|
options.UseInMemoryDatabase(_testDatabaseName);
|
|
options.EnableSensitiveDataLogging();
|
|
});
|
|
});
|
|
}
|
|
|
|
protected override IHost CreateHost(IHostBuilder builder)
|
|
{
|
|
var host = base.CreateHost(builder);
|
|
|
|
// Initialize databases after host is created
|
|
using var scope = host.Services.CreateScope();
|
|
var services = scope.ServiceProvider;
|
|
|
|
try
|
|
{
|
|
// Initialize Identity database
|
|
var identityDb = services.GetRequiredService<IdentityDbContext>();
|
|
identityDb.Database.EnsureCreated();
|
|
|
|
// Initialize ProjectManagement database
|
|
var pmDb = services.GetRequiredService<PMDbContext>();
|
|
pmDb.Database.EnsureCreated();
|
|
|
|
// Initialize IssueManagement database
|
|
var imDb = services.GetRequiredService<IssueManagementDbContext>();
|
|
imDb.Database.EnsureCreated();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error initializing test database: {ex.Message}");
|
|
throw;
|
|
}
|
|
|
|
return host;
|
|
}
|
|
}
|