Tactical DDD · .NET

Model an aggregate and test its invariants with xUnit

From a business scenario to transaction boundaries, using a marketing campaign.

A campaign can be scheduled only when it has a channel, valid content and a delivery time. This suggests a domain method such as Schedule. The xUnit test calls that method and observes whether the transition is allowed.

Keep data in the aggregate when its consistency is necessary during the transition. Member consent belongs to another model and can change before dispatch. The dispatch workflow must check it according to its own business rule.

Write one test for each condition that blocks scheduling. Add a successful scenario and an integration test if simultaneous edits must be detected by persistence.

A test named for the business behavior stays readable as storage, EF Core mappings and API formats change.

Reference documentation

All articles

Portfolio assistant