-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or requestfeatureThis label is in use for minor version incrementsThis label is in use for minor version increments
Milestone
Description
Title: Add Cortex.Mediator.Testing package with test doubles and assertions
Labels: enhancement, mediator, new-package
Body:
Problem
Testing code that depends on IMediator requires consumers to set up mocks (Moq, NSubstitute) for every test. Testing individual handlers requires manually constructing pipeline chains. There are no first-party test utilities.
Proposed Solution
Create a Cortex.Mediator.Testing package with:
FakeMediator -- Records all dispatched messages for assertions:
var mediator = new FakeMediator();
mediator.SetupCommandResult<CreateUserCommand, Guid>(cmd => Guid.NewGuid());
await sut.DoWork(mediator);
mediator.ShouldHaveSent<CreateUserCommand>(cmd => cmd.Name == "Alice");
mediator.ShouldHavePublished<UserCreatedNotification>();
mediator.ShouldNotHaveSent<DeleteUserCommand>();HandlerTestFixture<THandler> -- Isolated handler testing with automatic DI:
var fixture = new HandlerTestFixture<CreateUserCommandHandler>();
fixture.Register<IUserRepository>(mockRepo.Object);
var result = await fixture.HandleAsync(new CreateUserCommand { Name = "Alice" });Pipeline testing -- Assert behavior execution order:
var pipeline = PipelineAssert.ForCommand<CreateUserCommand, Guid>(services);
pipeline.ShouldExecuteInOrder(
typeof(LoggingBehavior<,>),
typeof(ValidationBehavior<,>),
typeof(CreateUserCommandHandler));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestfeatureThis label is in use for minor version incrementsThis label is in use for minor version increments