public async Task Send_FakeGenericCommand_ShouldGoThroughHandlersCorrectly() { // Arrange var serviceProvider = new ServiceCollection() .AddLiteBus(configuration => { configuration.AddCommands(builder => { // Global Handlers builder.RegisterPreHandler <FakeGlobalCommandPreHandler>(); builder.RegisterPostHandler <FakeGlobalCommandPostHandler>(); // Fake Command Handlers builder.RegisterPreHandler(typeof(FakeGenericCommandPreHandler <>)); builder.RegisterHandler(typeof(FakeGenericCommandHandlerWithoutResult <>)); builder.RegisterPostHandler(typeof(FakeGenericCommandPostHandler <>)); }); }) .BuildServiceProvider(); var commandMediator = serviceProvider.GetRequiredService <ICommandMediator>(); var command = new FakeGenericCommand <string>(); // Act var commandResult = await commandMediator.SendAsync(command); // Assert commandResult.CorrelationId.Should().Be(command.CorrelationId); command.ExecutedTypes.Should().HaveCount(5); command.ExecutedTypes[0].Should().Be <FakeGlobalCommandPreHandler>(); command.ExecutedTypes[1].Should().Be <FakeGenericCommandPreHandler <string> >(); command.ExecutedTypes[2].Should().Be <FakeGenericCommandHandlerWithoutResult <string> >(); command.ExecutedTypes[3].Should().Be <FakeGenericCommandPostHandler <string> >(); command.ExecutedTypes[4].Should().Be <FakeGlobalCommandPostHandler>(); }
public Task <FakeGenericCommandResult> HandleAsync(FakeGenericCommand <TPayload> message, CancellationToken cancellationToken = default) { message.ExecutedTypes.Add(typeof(FakeGenericCommandHandlerWithoutResult <TPayload>)); return(Task.FromResult(new FakeGenericCommandResult(message.CorrelationId))); }
public Task Handle(FakeGenericCommand <string> message, IMessageHandlerContext context) => throw new NotImplementedException();