Path: redb-identity/tests/redb.Identity.Tests/Http/Controllers/DisabledFeatureEndpointTests.cs Snapshot: redb-identity, 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-identity Page: https://redbase.app/src/dev-2026-12-06/redb-identity/tests/redb.Identity.Tests/Http/Controllers/DisabledFeatureEndpointTests.cs ---- using AwesomeAssertions; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using redb.Identity.Contracts.Common; using redb.Identity.Contracts.Routes; using redb.Identity.Contracts.Users; using redb.Identity.Management; using redb.Identity.Management.Controllers; using redb.Route.Abstractions; using redb.Route.Components; using Xunit; namespace redb.Identity.Tests.Http.Controllers; /// /// A feature that is switched off answers "no such endpoint", not a failure. /// /// Self-service registration, e-mail verification, e-mail change and WebAuthn bind their /// direct-vm:// routes only when enabled, while the facades mount their controllers /// regardless. A caller reaching a disabled feature therefore arrived at a producer with nothing /// behind it, and the InvalidOperationException that followed reached the client as a /// generic failure with an unhandled-exception stack trace in the log — observed on a running /// worker as POST /account/register answering 400 with /// No consumer registered for direct-vm endpoint 'identity-account-register'. /// /// /// The contract these tests pin is the one the client SDK already reads: 404, which /// IdentityClient.RegisterAccountAsync translates into registration_disabled. /// /// public class DisabledFeatureEndpointTests { private readonly IRouteContext _ctx = Substitute.For(); private readonly IEndpoint _endpoint = Substitute.For(); private readonly IProducer _producer = Substitute.For(); private readonly SharedVmRegistry _registry = new(); private readonly AccountRegistrationController _sut; public DisabledFeatureEndpointTests() { _ctx.GetEndpoint(IdentityEndpoints.AccountRegister).Returns(_endpoint); _endpoint.CreateProducer().Returns(_producer); // What the real DirectVmProducer does when the route was never bound. Reaching it at all // is the defect, so the substitute fails the same way instead of quietly succeeding. _producer.Process(Arg.Any(), Arg.Any()) .Returns(_ => throw new InvalidOperationException( "No consumer registered for direct-vm endpoint 'direct-vm://identity-account-register'.")); var sp = new ServiceCollection().AddSingleton(_registry).BuildServiceProvider(); _ctx.GetServiceProvider().Returns(sp); _sut = new AccountRegistrationController { Context = _ctx }; } private static RegisterAccountRequest Request() => new() { Login = "newcomer", Email = "newcomer@example.test", Password = "Test@Password123", }; [Fact] public async Task An_unbound_route_answers_not_found_instead_of_failing() { var result = await _sut.Register(Request()); var error = result.Should().BeOfType().Subject.Error; error.Should().Be("not_found", "the deployment does not expose this operation, which is a 404 and not an error the " + "caller can do anything about"); ManagementErrorCodes.ToStatusCode(error!).Should().Be(404, "this is the answer IdentityClient reads back as registration_disabled"); } [Fact] public async Task An_unbound_route_is_not_even_sent_to() { await _sut.Register(Request()); await _producer.DidNotReceive().Process(Arg.Any(), Arg.Any()); } [Fact] public async Task A_bound_route_is_forwarded_as_before() { // The guard must cost nothing when the feature is on: with a consumer in the registry the // call goes through to the producer exactly as it always did. IExchange? captured = null; _producer.Process(Arg.Do(e => captured = e), Arg.Any()) .Returns(Task.CompletedTask); _registry.TryRegisterProcessor(IdentityEndpoints.AccountRegister, Substitute.For()) .Should().BeTrue(); await _sut.Register(Request()); captured.Should().NotBeNull(); captured!.In.Headers["operation"].Should().Be("register"); } }