Ejemplo n.º 1
0
    public async Task Send_FakeGenericEvent_ShouldGoThroughHandlersCorrectly()
    {
        // Arrange
        var serviceProvider = new ServiceCollection()
                              .AddLiteBus(configuration =>
        {
            configuration.AddEvents(builder =>
            {
                // Global Handlers
                builder.RegisterPreHandler <FakeGlobalEventPreHandler>();
                builder.RegisterPostHandler <FakeGlobalEventPostHandler>();

                // Fake Event Handlers
                builder.RegisterPreHandler(typeof(FakeGenericEventPreHandler <>));
                builder.RegisterHandler(typeof(FakeGenericEventHandler1 <>));
                builder.RegisterHandler(typeof(FakeGenericEventHandler2 <>));
                builder.RegisterHandler(typeof(FakeGenericEventHandler3 <>));
                builder.RegisterPostHandler(typeof(FakeGenericEventPostHandler <>));
            });
        })
                              .BuildServiceProvider();

        var eventMediator = serviceProvider.GetRequiredService <IEventMediator>();
        var @event        = new FakeGenericEvent <string>();

        // Act
        await eventMediator.PublishAsync(@event);

        // Assert
        @event.ExecutedTypes.Should().HaveCount(7);
        @event.ExecutedTypes[0].Should().Be <FakeGlobalEventPreHandler>();
        @event.ExecutedTypes[1].Should().Be <FakeGenericEventPreHandler <string> >();
        @event.ExecutedTypes[2].Should().Be <FakeGenericEventHandler1 <string> >();
        @event.ExecutedTypes[3].Should().Be <FakeGenericEventHandler2 <string> >();
        @event.ExecutedTypes[4].Should().Be <FakeGenericEventHandler3 <string> >();
        @event.ExecutedTypes[5].Should().Be <FakeGenericEventPostHandler <string> >();
        @event.ExecutedTypes[6].Should().Be <FakeGlobalEventPostHandler>();
    }
Ejemplo n.º 2
0
 public Task HandleAsync(FakeGenericEvent <TPayload> message,
                         CancellationToken cancellationToken = default)
 {
     message.ExecutedTypes.Add(typeof(FakeGenericEventHandler3 <TPayload>));
     return(Task.CompletedTask);
 }
Ejemplo n.º 3
0
 public Task Handle(FakeGenericEvent <string> message, IMessageHandlerContext context) => throw new NotImplementedException();