Path: redb-identity/tests/redb.Identity.Tests/Http/Controllers/ApplicationsControllerTests.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/ApplicationsControllerTests.cs ---- using AwesomeAssertions; using NSubstitute; using redb.Identity.Contracts.Applications; using redb.Identity.Contracts.Common; using redb.Identity.Contracts.Routes; using redb.Identity.Management.Controllers;using redb.Route.Abstractions; using Xunit; namespace redb.Identity.Tests.Http.Controllers; public class ApplicationsControllerTests { private readonly IRouteContext _ctx = Substitute.For(); private readonly IEndpoint _endpoint = Substitute.For(); private readonly IProducer _producer = Substitute.For(); private readonly ApplicationsController _sut; private IExchange? _captured; public ApplicationsControllerTests() { _ctx.GetEndpoint(IdentityEndpoints.ManageApps).Returns(_endpoint); _endpoint.CreateProducer().Returns(_producer); _producer.Process(Arg.Do(e => _captured = e), Arg.Any()) .Returns(Task.CompletedTask); _sut = new ApplicationsController(); _sut.Context = _ctx; } [Fact] public async Task Get_NumericId_ForwardsWithNumericId() { await _sut.Get("42"); _captured!.In.Headers["operation"].Should().Be("read"); var body = _captured.In.Body as Dictionary; body.Should().NotBeNull(); body!["id"].Should().Be(42L); } [Fact] public async Task Get_StringId_ForwardsWithClientId() { await _sut.Get("my-app"); _captured!.In.Headers["operation"].Should().Be("read"); var body = _captured.In.Body as Dictionary; body.Should().NotBeNull(); body!["clientId"].Should().Be("my-app"); } [Fact] public async Task Update_SetsIdOnRequest() { var req = new UpdateApplicationRequest { DisplayName = "Updated" }; await _sut.Update("app-1", req); _captured!.In.Headers["operation"].Should().Be("update"); req.Id.Should().Be("app-1"); _captured.In.Body.Should().BeSameAs(req); } [Fact] public async Task Delete_NumericId_ForwardsWithNumericId() { await _sut.Delete("99"); _captured!.In.Headers["operation"].Should().Be("delete"); var body = _captured.In.Body as Dictionary; body!["id"].Should().Be(99L); } [Fact] public async Task Delete_StringId_ForwardsWithClientId() { await _sut.Delete("my-app"); _captured!.In.Headers["operation"].Should().Be("delete"); var body = _captured.In.Body as Dictionary; body!["clientId"].Should().Be("my-app"); } [Fact] public async Task Forward_SetsInOutPattern() { await _sut.List(); _captured!.Pattern.Should().Be(ExchangePattern.InOut); } [Fact] public async Task Forward_ReturnsOutBody_WhenAvailable() { _producer.Process(Arg.Any(), Arg.Any()) .Returns(ci => { var ex = ci.Arg(); // Simulate pipeline setting Out ex.Out = Substitute.For(); ex.Out.Body.Returns("result-data"); return Task.CompletedTask; }); var result = await _sut.List(); result.Should().Be("result-data"); } }