Skip to content

Using NServiceBus.Extensions.Hosting with Microsoft.AspNetCore.Mvc.Testing #323

@pardahlman

Description

@pardahlman

We are running ASP.NET Core applications that uses NServiceBus "send only" endpoints to publish events and send commands to RabbitMQ. NServiceBus is configured and started using this package.

We want to use ASP.NET Core integration test framework Microsoft.AspNetCore.Mvc.Testing to test these endpoints. The test framework uses the host configured in the entry point, but allows for updating DI configuration in the test before starting the application. This is useful when replacing unwanted integrations (for example database calls, ...) with mocks.

In these test we do not want to use RabbitMQ, but instead a more feasible transport (preferably some kind of in-memory transport). One important aspect that we want to test is that command routing has been correctly configured in the application.

To my knowledge, it is not possible to re-configure NServiceBus endpoint in the test: The EndpointConfiguration is never added to DI, HostAwareMessageSession is internal and also explicitly injected in NServiceBusHostedService so there is no way to intercept the startup process.

Do you have suggestions to how we can solve this issue? One suggestion that follows Microsoft conventions is to use Microsoft.Extensions.Options and "configure" EndpointConfiguration (services.Configure<EndpointConfiguration>(e => ...)). This would allow us to configure production transport in the entry point, and then override it with a new call to Configure in the test project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions