Skip to content

Add read model state seeding to command scenarios#2315

Merged
woksin merged 3 commits into
mainfrom
feat/command-scenario-read-model-seeding
Jun 28, 2026
Merged

Add read model state seeding to command scenarios#2315
woksin merged 3 commits into
mainfrom
feat/command-scenario-read-model-seeding

Conversation

@woksin

@woksin woksin commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Added

  • Command scenario tests can seed the read model state a command observes from events — Given.ForEventSource(id).Events(...) materializes any read model the command injects for that source through its own reducer or projection, with no read model type named.
  • Command scenario tests can pin a read model instance directly for a command with Given.ForEventSource(id).ReadModel(instance).

woksin and others added 3 commits June 28, 2026 12:04
Command-scoped code (handlers, validators, Provide methods) can take a read
model as a parameter; tests need to control what it contains. Add a Given
builder on the command scenario that sets that up two ways:

- Given.ForEventSource(id).Events(...) seeds events type-agnostically; any
  read model the command injects for that source is materialized from them
  through its own reducer or projection — no read model type is named.
- Given.ForEventSource(id).ReadModel(instance) pins a specific instance.

Read models resolve through a scenario IReadModels that projects seeded
events on demand or returns a pinned instance, keyed by event source id; an
unseeded source resolves to null so nullable read model parameters behave as
they do in production.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cover both seeding paths through the real command pipeline and reducer:

- events seeding into a handler, a validator (allow and reject), a read
  model with no parameterless constructor, and one set of events feeding
  multiple read models
- pinned instance into a handler, a Provide method, a validator (allow and
  reject), and a command targeting a different event source than the seeded
  one, which resolves to null

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the hand-mocked IReadModels guidance with the Given builder: seed
read model state from events or pin an instance. Update the testing extension
property tables and add a cross-link from the test-a-command recipe.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

NuGet packages for this PR, e.g. Cratis.Arc:
https://github.com/cratis/arc/packages/1655206?version=20.47.2

@woksin woksin merged commit 0ee383f into main Jun 28, 2026
52 checks passed
@woksin woksin deleted the feat/command-scenario-read-model-seeding branch June 28, 2026 10:25
@woksin woksin added the minor label Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant