Refactor nunit tests off InMemory/WebApplicationFactory, remove tuple returns (#4)
## Summary - Extract `IMicCheckDbContext` and mock DB access with Moq instead of the EF InMemory provider, per CLAUDE.md testing guidelines. - Rewrite HTTP-pipeline tests to exercise controllers/auth handlers directly instead of `WebApplicationFactory`. - Remove tuple return types across the API in favor of named records (`PagedResult<T>`, `ProfileUpdateResult`, `ApiKeyCreationResult`). ## Test plan - [x] `dotnet build` (full solution) - [x] `dotnet test tests/api/MicCheck.Api.Tests.Unit` — 187/187 pass - [x] `dotnet test tests/api/MicCheck.Api.Tests.Integration` — 8/8 pass (live API + Postgres via Aspire) - [x] Verified Aspire AppHost/dashboard starts and API responds Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
@@ -13,7 +13,7 @@ using AppEnvironment = MicCheck.Api.Environments.Environment;
|
||||
|
||||
namespace MicCheck.Api.Data;
|
||||
|
||||
public class MicCheckDbContext : DbContext
|
||||
public class MicCheckDbContext : DbContext, IMicCheckDbContext
|
||||
{
|
||||
public MicCheckDbContext(DbContextOptions<MicCheckDbContext> options) : base(options) { }
|
||||
|
||||
@@ -42,3 +42,31 @@ public class MicCheckDbContext : DbContext
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
=> modelBuilder.ApplyConfigurationsFromAssembly(typeof(MicCheckDbContext).Assembly);
|
||||
}
|
||||
|
||||
public interface IMicCheckDbContext
|
||||
{
|
||||
DbSet<Organization> Organizations { get; }
|
||||
DbSet<OrganizationUser> OrganizationUsers { get; }
|
||||
DbSet<Project> Projects { get; }
|
||||
DbSet<AppEnvironment> Environments { get; }
|
||||
DbSet<Feature> Features { get; }
|
||||
DbSet<FeatureState> FeatureStates { get; }
|
||||
DbSet<FeatureSegment> FeatureSegments { get; }
|
||||
DbSet<Tag> Tags { get; }
|
||||
DbSet<Segment> Segments { get; }
|
||||
DbSet<SegmentRule> SegmentRules { get; }
|
||||
DbSet<SegmentCondition> SegmentConditions { get; }
|
||||
DbSet<Identity> Identities { get; }
|
||||
DbSet<IdentityTrait> IdentityTraits { get; }
|
||||
DbSet<AuditLog> AuditLogs { get; }
|
||||
DbSet<Webhook> Webhooks { get; }
|
||||
DbSet<WebhookDeliveryLog> WebhookDeliveryLogs { get; }
|
||||
DbSet<ApiKey> ApiKeys { get; }
|
||||
DbSet<User> Users { get; }
|
||||
DbSet<RefreshToken> RefreshTokens { get; }
|
||||
DbSet<UserProjectPermission> UserProjectPermissions { get; }
|
||||
DbSet<FeatureUsageDaily> FeatureUsageDaily { get; }
|
||||
|
||||
int SaveChanges();
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user