Skip to main content

Employee Database Testing Guide

Summary

Validate Employee persistence only in disposable or isolated non-production databases with synthetic data and approved tenant context. No formal .NET test project was found in the reviewed backend tree.

Audience

  • QA and backend engineers
  • DevOps engineers validating migrations

Prerequisites

  • An isolated PostgreSQL test instance managed through the approved test environment.
  • A build containing the exact migrations under review.
  • Synthetic tenant and Employee inputs with no copied customer or personal data.
  • A cleanup or environment-reset mechanism owned by the test environment.

Steps

Unit tests

  • Exercise Employee code/name/contact value validation, status transitions, self-manager rejection, and document/note invariants without persistence.
  • Verify aggregate methods stamp Employee and tenant identity onto replacement child collections.
  • Verify domain changes queue expected event categories without asserting payload bodies in this epic.

Repository integration tests

  • Create and retrieve a full aggregate with each child collection.
  • Confirm unique Employee code at both application and database levels.
  • Confirm duplicate email is rejected by the application and separately record that no database unique constraint exists.
  • Reject inactive/missing department, designation, and manager references through command paths.
  • Confirm self-manager rejection.
  • Force a failure before the unit-of-work save completes and verify business, audit, timeline, and outbox changes do not partially persist.
  • Verify timeline/audit/outbox creation for representative successful commands without inspecting sensitive content.
  • Exercise search filtering, child skill filtering, normalized paging, sorting, and empty pages.

Migration tests

  • Build an empty schema through both committed migrations.
  • Upgrade a database at the initial migration to the timeline migration.
  • Compare the resulting EF model with the committed snapshot.
  • Verify all 13 objects, 17 indexes, eight child foreign keys, and expected uniqueness.
  • Test representative existing timeline values against the later length constraints.

Tenant-isolation tests

  • Create equal business codes in two tenants and verify both are allowed.
  • Verify normal queries return only the active tenant's roots, children, organization rows, timeline, and audit.
  • Verify repository uniqueness checks remain tenant-specific despite filter bypass.
  • Test approved super-admin query behavior separately; do not treat it as ordinary tenant access.

Backfill and parity tests

  • Compare source and target counts by tenant and active state.
  • Verify deterministic identifier reconciliation without assuming numeric/GUID equivalence.
  • Compare organization assignments and unresolved references.
  • Re-run the approved transformation to prove idempotency before cutover.
  • Record skipped or invalid rows explicitly; no Employee backfill implementation currently exists.

Validation or Expected Result

Tests should demonstrate tenant isolation, verified database constraints, application-only email uniqueness, child cascade relationships, atomic local commits, correct migration shape, and explicit parity exceptions. They must not assert broker delivery from outbox row creation alone.

Troubleshooting

If migration output differs from the snapshot, a logical reference resolves only in another tenant, or a compatibility identifier lacks a deterministic mapping, stop and classify the result as Requires confirmation. Do not repair test results by directly editing production-like data.

Source References

  • microservices/src/employee-service/Domain/Employees/Employee.cs
  • microservices/src/employee-service/Application/Validators/EmployeeCommandValidators.cs
  • microservices/src/employee-service/Infrastructure/EmployeeDbContext.cs
  • microservices/src/employee-service/Infrastructure/Persistence.cs
  • microservices/src/employee-service/Infrastructure/PostgresEmployeeSearchProvider.cs
  • microservices/src/employee-service/Infrastructure/Migrations/
  • microservices/scripts/smoke-employee.ps1

See Also

Keywords

  • Repository integration testing
  • Migration validation
  • Tenant isolation testing

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-15
  • Review cycle: Quarterly