Test Double Options for Command Processor
Overview
Installation
<PackageReference Include="Paramore.Brighter.Testing" /><ProjectReference Include="..\..\src\Paramore.Brighter.Testing\Paramore.Brighter.Testing.csproj" />Using SpyCommandProcessor
Basic Usage
// Arrange
var spy = new SpyCommandProcessor();
var handler = new PlaceOrderHandler(spy);
var command = new PlaceOrder { ProductId = "WIDGET-1", Quantity = 3 };
// Act
handler.Handle(command);
// Assert - verify the handler published an OrderPlaced event
spy.WasCalled(CommandType.Publish).ShouldBeTrue();
var published = spy.Observe<OrderPlaced>();
published.ProductId.ShouldBe("WIDGET-1");API Layers
Layer 1: Quick Checks
Layer 2: Request Inspection
Layer 3: Full Details
CommandType Values
Method
CommandType
Verifying Send/Publish/Post Calls
Verifying Send
Verifying Publish
Verifying Post (External Bus)
Verifying the Outbox Pattern (DepositPost + ClearOutbox)
State Management
Extending SpyCommandProcessor
Alternative: Using Mocking Frameworks
Moq
NSubstitute
Best Practices
Last updated
Was this helpful?
