dc8f3466c9
- Added IdentityAccessModule.cs with DI registration - Added KArtSell.Modules.IdentityAccess.csproj with FastEndpoints deps - Added project files for UnitTests & IntegrationTests - Updated Program.cs to register IdentityAccessModule - Updated Host.csproj to reference IdentityAccess module - Fixed Directory.Packages.props with Moq + MS.Extensions.DependencyInjection ISSUES (to fix next session): - FastEndpoints Send/SendAsync/SendOkAsync method resolution incomplete - Response record initialization requires field values - Need to refactor endpoints to match ModelOperations pattern exactly WORKING: - Domain layer (IdentityState, RoleAssignmentState) ✅ - SQL repositories (Dapper) ✅ - Unit tests (RegisterIdentity, RequestMfaSetup handlers) ✅ - Integration test structure ready ✅ Next: Simplify endpoints using 'Endpoint<Req,Resp>' pattern from GetApprovalQueue sample Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
112 lines
3.8 KiB
C#
112 lines
3.8 KiB
C#
using Xunit;
|
|
using Npgsql;
|
|
using Dapper;
|
|
using KArtSell.Modules.IdentityAccess.ManageIdentityAndRoles.Features.RegisterIdentity;
|
|
using System.Data;
|
|
|
|
namespace KArtSell.IdentityAccess.IntegrationTests.ManageIdentityAndRoles;
|
|
|
|
[Collection("Database")]
|
|
public class RegisterIdentityIntegrationTests : IAsyncLifetime
|
|
{
|
|
private readonly string _connectionString;
|
|
private NpgsqlDataSource _dataSource = null!;
|
|
private RegisterIdentitySql _sql = null!;
|
|
|
|
public RegisterIdentityIntegrationTests()
|
|
{
|
|
_connectionString = Environment.GetEnvironmentVariable("KARTSELL_POSTGRES")
|
|
?? "Host=127.0.0.1;Port=5432;Database=kartselldb;Username=postgres;Password=postgres";
|
|
}
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
_dataSource = new NpgsqlDataSourceBuilder(_connectionString).Build();
|
|
_sql = new RegisterIdentitySql(async () => await _dataSource.OpenConnectionAsync());
|
|
|
|
await CleanupAsync();
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
await CleanupAsync();
|
|
await _dataSource.DisposeAsync();
|
|
}
|
|
|
|
private async Task CleanupAsync()
|
|
{
|
|
using var conn = await _dataSource.OpenConnectionAsync();
|
|
await conn.ExecuteAsync("DELETE FROM identity.identity WHERE email LIKE 'test-integration-%'");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateIdentity_ValidRequest_InsertsAndReturnsId()
|
|
{
|
|
var email = "test-integration-001@example.com";
|
|
var displayName = "Test User 001";
|
|
var correlationId = Guid.NewGuid().ToString();
|
|
var identityId = Guid.NewGuid();
|
|
|
|
var createdId = await _sql.CreateIdentityAsync(identityId, email, displayName, correlationId, CancellationToken.None);
|
|
|
|
Assert.NotEqual(Guid.Empty, createdId);
|
|
Assert.Equal(identityId, createdId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateIdentity_DuplicateEmail_ReturnsEmpty()
|
|
{
|
|
var email = "test-integration-002@example.com";
|
|
var displayName = "Test User 002";
|
|
var correlationId = Guid.NewGuid().ToString();
|
|
|
|
var id1 = Guid.NewGuid();
|
|
var id2 = Guid.NewGuid();
|
|
|
|
var created1 = await _sql.CreateIdentityAsync(id1, email, displayName, correlationId, CancellationToken.None);
|
|
var created2 = await _sql.CreateIdentityAsync(id2, email, displayName, correlationId, CancellationToken.None);
|
|
|
|
Assert.Equal(id1, created1);
|
|
Assert.Equal(Guid.Empty, created2);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetIdentity_AfterCreate_ReturnsCorrectData()
|
|
{
|
|
var email = "test-integration-003@example.com";
|
|
var displayName = "Test User 003";
|
|
var correlationId = Guid.NewGuid().ToString();
|
|
var identityId = Guid.NewGuid();
|
|
|
|
await _sql.CreateIdentityAsync(identityId, email, displayName, correlationId, CancellationToken.None);
|
|
var (id, returnedEmail, returnedDisplayName, state) = await _sql.GetIdentityAsync(identityId, CancellationToken.None);
|
|
|
|
Assert.Equal(identityId, id);
|
|
Assert.Equal(email, returnedEmail);
|
|
Assert.Equal(displayName, returnedDisplayName);
|
|
Assert.Equal("ACTIVE", state);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task EmailExists_WithExistingEmail_ReturnsTrue()
|
|
{
|
|
var email = "test-integration-004@example.com";
|
|
var displayName = "Test User 004";
|
|
var correlationId = Guid.NewGuid().ToString();
|
|
var identityId = Guid.NewGuid();
|
|
|
|
await _sql.CreateIdentityAsync(identityId, email, displayName, correlationId, CancellationToken.None);
|
|
var exists = await _sql.EmailExistsAsync(email, CancellationToken.None);
|
|
|
|
Assert.True(exists);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task EmailExists_WithNonExistentEmail_ReturnsFalse()
|
|
{
|
|
var exists = await _sql.EmailExistsAsync("nonexistent-integration-001@example.com", CancellationToken.None);
|
|
|
|
Assert.False(exists);
|
|
}
|
|
}
|