Path: redb-identity/tests/redb.Identity.Tests/Routes/MeProfileProcessorTests.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/Routes/MeProfileProcessorTests.cs
----
using AwesomeAssertions;
using redb.Identity.Core.Routes.Processors;
using redb.Route.Core;
using Xunit;
namespace redb.Identity.Tests.Routes;
///
/// H3 (v1.0 DoD ยง6) unit tests for . Covers the
/// caller-id precondition paths (missing / non-positive) which reject before
/// any access, so no DB or service wiring is required.
/// Happy-path read/update flows live in the integration suite.
///
public sealed class MeProfileProcessorTests
{
private static Exchange BuildExchange(long? userId, string operation, object? body = null)
{
var ex = new Exchange(new Message { Body = body ?? new Dictionary() });
ex.In.Headers["operation"] = operation;
if (userId is not null)
ex.Properties["identity:management-user-id"] = userId.Value;
return ex;
}
[Fact]
public async Task MissingSubject_Returns401()
{
var sut = new MeProfileProcessor(context: null!, redbName: null);
var ex = BuildExchange(userId: null, operation: "read");
await sut.Process(ex);
ex.HasOut.Should().BeTrue();
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
ex.IsStopped.Should().BeTrue();
var body = (Dictionary)ex.Out.Body!;
body["error"].Should().Be("invalid_token");
}
[Fact]
public async Task NonPositiveSubject_Returns401()
{
var sut = new MeProfileProcessor(context: null!, redbName: null);
var ex = BuildExchange(userId: 0, operation: "update");
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
}
[Fact]
public async Task NegativeSubject_Returns401()
{
var sut = new MeProfileProcessor(context: null!, redbName: null);
var ex = BuildExchange(userId: -7, operation: "read");
await sut.Process(ex);
ex.Out!.Headers["redbHttp.ResponseCode"].Should().Be(401);
}
}