So actually it is not possible to not start NSB when using UseNServiceBus. Only alternative is to check environment (e.g. Development) and add learning tranpost instead, right? I don’t put test code in my production code, so what to do then?
My comment regarding just using
Build was based on your described need to only resolve handlers from the DI container to invoke them manually, which would be possible with that. If you want to start the endpoint normally, then the generic host needs to be started, yes.
I think it might be easiest to just “copy” the endpoint configuration (or extract it into a shared class/method) and then overwrite the transport settings with the learning transport in the acceptance test-specific
The host is really just a host and not an existential part of your application logic, so it should be ok to use a different host for your testing needs.
learning transport, might be handy later, but actually the handlers are very primitive and does not send messages. Also tests are run in parallel, could be fixed with different learning transport configurations.
If you just want to test your fairly simple handlers, I think it would be a lot easier to just go with “unit tests” (the name might be misleading). Creating the instances, managing the dependencies etc. for testing purpose will be more straight forward (see Testing NServiceBus • Testing • Particular Docs). If your goal is to run with acceptance or integration tests, the NServiceBus endpoint should be fully started and handlers should be invoked by sending the message via the transport.