コード例 #1
0
    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>();
    }
コード例 #2
0
 public Task <FakeGenericCommandResult> HandleAsync(FakeGenericCommand <TPayload> message,
                                                    CancellationToken cancellationToken = default)
 {
     message.ExecutedTypes.Add(typeof(FakeGenericCommandHandlerWithoutResult <TPayload>));
     return(Task.FromResult(new FakeGenericCommandResult(message.CorrelationId)));
 }
コード例 #3
0
 public Task Handle(FakeGenericCommand <string> message, IMessageHandlerContext context) => throw new NotImplementedException();