PropertyDamage.MockServiceRegistry (PropertyDamage v0.2.0)
View SourceRegistry for managing mock service adapters and their state.
The MockServiceRegistry:
- Manages state for all active mock adapters
- Collects events injected by mocks
- Notifies mocks of commands and events
- Provides projection state to mocks for request handling
Lifecycle
start_link/1- Start the registryregister/2- Register mock adapters- During execution:
notify_command/2- Inform mocks of commandsupdate_projections/2- Share projection statepush_event/3- Mocks inject eventsflush_events/1- Executor collects injected eventsnotify_event/2- Inform mocks of events
stop/1- Stop the registry
Usage
{:ok, registry} = MockServiceRegistry.start_link([])
# Register mock adapters
MockServiceRegistry.register(registry, PaymentMock)
MockServiceRegistry.register(registry, EmailMock)
# During test execution
MockServiceRegistry.notify_command(registry, command)
MockServiceRegistry.update_projections(registry, projections)
# Mock calls push_event when SUT calls them
MockServiceRegistry.push_event(registry, PaymentMock, %PaymentProcessed{})
# Executor collects injected events
events = MockServiceRegistry.flush_events(registry)
# Notify mocks of events
for event <- events do
MockServiceRegistry.notify_event(registry, event)
end
Summary
Functions
Returns a specification to start this module under a supervisor.
Flush all pending injected events.
Get the combined state for request handling.
Get the current state for a mock adapter.
Notify all mocks of a command being executed.
Notify all mocks of an event.
Push an event from a mock adapter.
Push multiple events from a mock adapter.
Register a mock adapter with the registry.
Start the mock service registry.
Stop the registry.
Unregister a mock adapter.
Update the projection state available to mocks.
Update the state for a mock adapter.
Types
@type t() :: pid()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Flush all pending injected events.
Returns events in the order they were pushed. Events are cleared from the registry after flushing.
Get the combined state for request handling.
Returns mock state merged with current projections.
Get the current state for a mock adapter.
Used by mock handlers to access their state during request handling.
Notify all mocks of a command being executed.
Each mock's on_command/2 is called with the command.
Notify all mocks of an event.
Each mock's on_event/2 is called with the event.
Push an event from a mock adapter.
Called by mock adapters when they inject events.
Push multiple events from a mock adapter.
Register a mock adapter with the registry.
The adapter's init_state/0 is called to initialize its state.
Start the mock service registry.
Options
:name- Optional name for the registry process
@spec stop(t()) :: :ok
Stop the registry.
Unregister a mock adapter.
Update the projection state available to mocks.
Called after each command execution so mocks have current state.
Update the state for a mock adapter.
Used by mock handlers if they need to update state during request handling.