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));
Title: Add Cortex.Mediator.Testing package with test doubles and assertions
Labels:
enhancement,mediator,new-packageBody:
Problem
Testing code that depends on
IMediatorrequires 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.Testingpackage with:FakeMediator-- Records all dispatched messages for assertions:HandlerTestFixture<THandler>-- Isolated handler testing with automatic DI:Pipeline testing -- Assert behavior execution order: