File tree Expand file tree Collapse file tree
tests/Vulthil.Messaging.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,9 +6,12 @@ internal sealed class ConsumerHostedService : BackgroundService
66{
77 private readonly ITransport _transport ;
88
9- public ConsumerHostedService ( ITransport transport )
9+ public ConsumerHostedService ( IEnumerable < ITransport > transports )
1010 {
11- _transport = transport ;
11+ _transport = transports . LastOrDefault ( )
12+ ?? throw new InvalidOperationException (
13+ "No messaging transport is registered. Call a transport extension such as .UseRabbitMq(...) " +
14+ "inside AddMessaging(...) (or .UseTestHarness() in a test)." ) ;
1215 }
1316
1417 protected override Task ExecuteAsync ( CancellationToken stoppingToken ) => _transport . StartAsync ( stoppingToken ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ public static class DependencyInjection
2222 /// Code registrations performed inside the configurator action merge onto the loaded values and take precedence.
2323 /// Built-in consume filters (see <see cref="ConsumeFilterOptions"/>) are registered before the configurator
2424 /// action runs, so user-registered filters compose INSIDE the defaults.
25+ /// <para>A transport must be configured — e.g. <c>UseRabbitMq(...)</c> inside the configurator, or registered
26+ /// separately (as <c>ReplaceTransportWithTestHarness</c> does) — otherwise the host fails to start with a clear
27+ /// error.</para>
2528 /// </remarks>
2629 /// <param name="builder">The host application builder.</param>
2730 /// <param name="messagingConfiguratorAction">An action to configure messaging through <see cref="IMessagingConfigurator"/>.</param>
Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ public void AddMessagingShouldRegisterConsumerHostedService()
2929 hostedServices [ 0 ] . Lifetime . ShouldBe ( ServiceLifetime . Singleton ) ;
3030 }
3131
32+ [ Fact ]
33+ public async Task StartingTheHostWithoutATransportThrowsAClearError ( )
34+ {
35+ // Arrange — messaging configured, but no transport (no UseRabbitMq/UseTestHarness).
36+ Target . AddMessaging ( x => x . ConfigureQueue ( "orders" , _ => { } ) ) ;
37+ using var host = Target . Build ( ) ;
38+
39+ // Act & Assert
40+ var exception = await Should . ThrowAsync < InvalidOperationException > ( ( ) => host . StartAsync ( CancellationToken ) ) ;
41+ exception . Message . ShouldContain ( "No messaging transport is registered" ) ;
42+ }
43+
3244 [ Fact ]
3345 public void AddMessagingShouldRegisterMessageConfigurationProvider ( )
3446 {
You can’t perform that action at this time.
0 commit comments