Skip to main content

Leave Event Integration Testing Guide

Summary​

This guide covers the verified event surface in isolated test environments. No formal Leave-specific .NET test project was found; a Leave smoke script exists.

Audience​

Developers, QA, architects, consumer owners, and integration-test engineers.

Prerequisites​

Use current shared contracts, disposable persistence, synthetic identities, isolated broker infrastructure or test doubles, and controllable Employee/Attendance/Workflow/Payroll/Notification dependencies. Never run these scenarios against production.

Steps​

Unit tests​

  • Assert exact domain-event creation for request creation, initial/direct/Workflow decisions, cancellation, balance methods, and Encashment Foundation creation.
  • Assert invalid state/validation paths raise no event.
  • Verify all six one-to-one mappings, source identity behavior, correlation/causation values, and schema version 1.

Persistence integration tests​

  • Verify aggregate/history/outbox atomicity within one SaveChanges and rollback on failure.
  • Verify decision and later balance saves can succeed/fail independently and produce separate events.
  • Confirm event identity uniqueness, Pending/Failed polling, processed/failed transitions, and serialized contract round-trip.

Contract tests​

  • Serialize/deserialize all six Leave and three inbound Employee contracts.
  • Test additive/missing/unknown fields, numeric identity context, dates/decimals, nullable envelope fields, and version fallback.
  • Validate consumers against current and previous approved fixtures without personal data.

Broker and consumer tests​

  • Test successful publication, unavailable broker, retry, duplicate delivery, out-of-order delivery, missing consumer, and consumer failure.
  • Employee: insert/update/status, duplicate/stale, invalid tenant/identity, requeue, and no deletion subscription.
  • Payroll: approved/rejected/cancelled updates, EventId duplicate, stale snapshot, missing identity, and decision-order permutations.
  • Notification: approved/rejected intent, unsupported Leave events, duplicate/stale, suppressed/missing-template outcomes, bounded delivery retry, and persisted failure.

Workflow and end-to-end tests​

  • Test Workflow start/correlation, callback approval/rejection, duplicate terminal callback, verification mismatch, callback failure, decision publication, and separate balance publication.
  • Test request creation through consumer-observed outcomes, delayed publication, unavailable downstream consumers, and recovery.
  • Smoke-test the confirmed Leave smoke script in an approved non-production environment.
  • Cutover tests must compare monolith/extracted behavior without assuming shared event publication or synchronized stores.

Validation or Expected Result​

Expected totals are six domain events, six outbound contracts, six mappings, three inbound Employee contracts, five confirmed outbound subscriptions across two services, and version 1 mappings. No test should infer delivery completion from a processed Leave outbox row.

Troubleshooting​

When results differ, verify source contract version, mapped event type, outbox commit, relay result, broker metadata versus payload, subscription list, EventId handling, stale policy, consumer persistence, and multi-save timing. Mark unexplained topology, replay, or cutover behavior Requires confirmation.

Source References​

  • microservices/src/leave-service/Domain/Leave/LeaveDomainEvents.cs
  • microservices/src/contracts/Events/LeaveLifecycleEvents.cs
  • microservices/src/leave-service/Infrastructure/LeaveDbContext.cs
  • microservices/src/shared-kernel/Messaging/OutboxProcessor.cs
  • microservices/src/leave-service/Messaging/EmployeeProfileConsumer.cs
  • microservices/src/payroll-service/Messaging/PayrollReadModelConsumer.cs
  • microservices/src/notification-service/Application/NotificationDispatcher.cs
  • microservices/scripts/smoke-leave.ps1

See Also​

Keywords​

  • Event testing
  • Contract testing
  • Consumer testing

Revision Information​

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