๐ก๏ธ Test Structure & Application Quality
Quality in InventoryAlert is enforced through a comprehensive, multi-layered approach. We have consolidated our testing infrastructure into a single, high-performance integration project that covers everything from static architecture analysis to full system orchestration.
๐๏ธ Test Solution Structureโ
The solution is divided into three core testing projects:
1. InventoryAlert.UnitTests (Isolated Logic)โ
Goal: Verify pure business logic, calculations, and state changes with 100% mocked dependencies.
- Scope: Handles edge cases, null inputs, and finance math accuracy (e.g.,
PercentDropFromCost). - Speed: Instant feedback (< 2 seconds for full suite).
2. InventoryAlert.IntegrationTests (Unified System Tests)โ
Goal: Verify that the application communicates correctly with its persistence (Postgres/Redis) and messaging (SQS/SNS) layers.
- Architecture: Organized into Three Logical Tiers (see Integration Testing Tiers):
- Tier 1 (White-box): Direct logic testing using production DI.
- Tier 2 (Black-box): API surface testing with log-correlation.
- Tier 3 (Orchestration): End-to-end "Whole Flow" validation.
- Isolation: Uses Respawn for DB reset and WireMock for external API simulation.
3. InventoryAlert.ArchitectureTests (Static Enforcement)โ
Goal: Prevent architectural drift and tech debt using NetArchTest.
- Enforcement: Ensures
Domainnever referencesInfrastructureand all controllers are secured with[Authorize].
๐ก๏ธ Comprehensive Quality Coverage Matrixโ
How we guarantee quality across different operational domains:
| Domain/Component | How Quality is Ensured |
|---|---|
| Business Logic | Tier 1 Integration tests resolve real services from the production DI graph to verify logic against a real DB. |
| Database Integrity | Respawn ensures every test starts with a clean DB. Tier 1/2 tests verify EF Core constraints and complex LINQ queries. |
| External APIs | WireMock simulates Finnhub. We test success paths, 429 rate limits, and 500 server errors without hitting real endpoints. |
| System Orchestration | Tier 3 tests verify the Whole Flow: API Call โ SQS โ Worker Job โ DB Update โ API Notification Feed. |
| Observability | DockerLogReader allows tests to "scrape" container logs, proving that internal request traces (CorrelationId) are correctly logged. |
๐ Measuring Quality: Code Coverageโ
We use Coverlet and ReportGenerator to visualize coverage.
- Script: Run
./code-coverage.batfrom the root. - Target: 80%+ coverage in the
DomainandApplicationlayers.
โ๏ธ Automated Quality Gates (CI/CD)โ
Every Pull Request is blocked until the following passes:
- Build & Lint: Next.js and .NET 10 compilation.
- Architecture Check: Runs
NetArchTestrules. - Unit Tests: Executes isolated logic tests.
- Integration Suite: Spins up the full Docker stack and executes all 3 Tiers of integration tests to prove "Whole-Flow" stability.
๐ฉบ Runtime Quality (Observability)โ
- Structured Logging (Seq): Trace single user actions across projects via
CorrelationId. - Health Checks (
/health): Active probes for Postgres, Redis, and SQS connectivity. - DLQ isolation: Poison messages are moved to
inventory-event-dlqto prevent worker crash loops.