Path: redb-identity/tests/redb.Identity.Tests/Pipeline/AppManagementPipelineTests.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/Pipeline/AppManagementPipelineTests.cs
----
using AwesomeAssertions;
using NSubstitute;
using redb.Core.Models.Entities;
using redb.Identity.Contracts.Applications;
using redb.Identity.Contracts.Common;
using redb.Identity.Core.Models;
using redb.Identity.Contracts.Routes;
using redb.Identity.Tests.Infrastructure;
using Xunit;
namespace redb.Identity.Tests.Pipeline;
///
/// Application management through the full route pipeline.
/// Validates: route wiring → processor → WireTap → event dispatch.
///
[Collection("IdentityRoute")]
public class AppManagementPipelineTests
{
private readonly IdentityRouteFixture _fixture;
public AppManagementPipelineTests(IdentityRouteFixture fixture) => _fixture = fixture;
[Fact]
public async Task CreateApp_ThroughPipeline_ReturnsApplicationResponse()
{
MockRedbQuery.Setup(_fixture.Redb, new List>());
_fixture.Redb.SaveAsync(Arg.Any>())
.Returns(ci => { ci.Arg>().Id = 100; return 100L; });
var exchange = await _fixture.RequestWithHeaders(
IdentityEndpoints.ManageApps,
new CreateApplicationRequest
{
ClientId = "pipeline-app",
ClientSecret = "secret",
ClientType = "confidential",
DisplayName = "Pipeline App"
},
new Dictionary { ["operation"] = "create" });
exchange.Exception.Should().BeNull();
var resp = exchange.In.Body.Should().BeOfType().Subject;
resp.ClientId.Should().Be("pipeline-app");
resp.DisplayName.Should().Be("Pipeline App");
}
[Fact]
public async Task CreateApp_MissingClientId_ReturnsError()
{
var exchange = await _fixture.RequestWithHeaders(
IdentityEndpoints.ManageApps,
new CreateApplicationRequest { ClientId = "" },
new Dictionary { ["operation"] = "create" });
exchange.Exception.Should().BeNull();
var body = exchange.In.Body.Should().BeOfType().Subject;
body.Error.Should().Be("validation_error");
}
[Fact]
public async Task ReadApp_ById_ReturnsApplication()
{
var app = MockRedbQuery.CreateObject(42, "Test",
new ApplicationProps { ClientId = "read-pipeline" });
_fixture.Redb.LoadAsync(42).Returns(app);
var exchange = await _fixture.RequestWithHeaders(
IdentityEndpoints.ManageApps,
new Dictionary { ["id"] = 42L },
new Dictionary { ["operation"] = "read" });
exchange.Exception.Should().BeNull();
var resp = exchange.In.Body.Should().BeOfType().Subject;
resp.ClientId.Should().Be("read-pipeline");
}
[Fact]
public async Task ListApps_ThroughPipeline_ReturnsPaginated()
{
var items = Enumerable.Range(1, 3)
.Select(i => MockRedbQuery.CreateObject(i, $"App{i}",
new ApplicationProps { ClientId = $"list-{i}" }))
.ToList();
MockRedbQuery.Setup(_fixture.Redb, items);
var exchange = await _fixture.RequestWithHeaders(
IdentityEndpoints.ManageApps,
new ListRequest { Offset = 0, Count = 10 },
new Dictionary { ["operation"] = "list" });
exchange.Exception.Should().BeNull();
var result = exchange.In.Body.Should().BeOfType>().Subject;
result.Total.Should().Be(3);
result.Items.Should().HaveCount(3);
}
[Fact]
public async Task DeleteApp_ThroughPipeline_ReturnsSuccess()
{
// The delete looks the record up first; it exists and is of this resource.
_fixture.Redb.LoadAsync(55).Returns(new RedbObject(new ApplicationProps()) { id = 55 });
_fixture.Redb.DeleteAsync(55).Returns(true);
// The delete revokes the client's tokens first; this client has none.
MockRedbQuery.Setup(_fixture.Redb, new List>());
var exchange = await _fixture.RequestWithHeaders(
IdentityEndpoints.ManageApps,
new Dictionary { ["id"] = 55L },
new Dictionary { ["operation"] = "delete" });
exchange.Exception.Should().BeNull();
var body = exchange.In.Body.Should().BeOfType().Subject;
body.Success.Should().BeTrue();
}
[Fact]
public async Task UnknownOperation_ThroughPipeline_ReturnsError()
{
var exchange = await _fixture.RequestWithHeaders(
IdentityEndpoints.ManageApps,
null,
new Dictionary { ["operation"] = "nuke" });
exchange.Exception.Should().BeNull();
var body = exchange.In.Body.Should().BeOfType().Subject;
body.Error.Should().Be("invalid_operation");
}
}