Path: redb-route/tests/redb.Route.Tests.AzureServiceBus/AzureServiceBusFailedStartTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.AzureServiceBus/AzureServiceBusFailedStartTests.cs ---- using Azure.Messaging.ServiceBus; using redb.Route.Abstractions; using redb.Route.AzureServiceBus; using redb.Route.Core; namespace redb.Route.Tests.AzureServiceBus; /// /// A consumer whose processor refuses to start lets that processor go: it is disposed, and a later start creates one new /// processor instead of a second beside a half-started one. Driven by a fake through the /// endpoint's ClientSource, no namespace needed. /// public sealed class AzureServiceBusFailedStartTests { private static (AzureServiceBusEndpoint Endpoint, List Processors) Endpoint(bool firstStartFails) { var processors = new List(); var client = Substitute.For(); client.CreateProcessor(Arg.Any(), Arg.Any()).Returns(_ => { var processor = Substitute.For(); processor.StartProcessingAsync(Arg.Any()).Returns( firstStartFails && processors.Count == 0 ? Task.FromException(new ServiceBusException("entity not found", ServiceBusFailureReason.MessagingEntityNotFound)) : Task.CompletedTask); processors.Add(processor); return processor; }); var endpoint = (AzureServiceBusEndpoint)new AzureServiceBusComponent().CreateEndpoint( EndpointUriParser.Parse("asb://orders?connectionString=Endpoint=sb://test")); endpoint.ClientSource = () => client; return (endpoint, processors); } [Fact] public async Task A_processor_that_fails_to_start_is_disposed_and_the_next_start_creates_one() { var (endpoint, processors) = Endpoint(firstStartFails: true); var consumer = endpoint.CreateConsumer(Substitute.For()); var first = () => consumer.Start(); await first.Should().ThrowAsync(); processors.Should().ContainSingle(); await processors[0].Received(1).DisposeAsync(); await consumer.Start(); processors.Should().HaveCount(2, "the second start creates one new processor"); await processors[1].Received(1).StartProcessingAsync(Arg.Any()); await processors[1].DidNotReceive().DisposeAsync(); } }