Path: redb-identity/tests/redb.Identity.Tests/Management/ResultContractsParityTests.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/Management/ResultContractsParityTests.cs
----
using System.Text.Encodings.Web;
using System.Text.Json;
using AwesomeAssertions;
using redb.Identity.Contracts.ClaimMappers;
using redb.Identity.Contracts.Common;
using redb.Identity.Contracts.Consents;
using redb.Identity.Contracts.Federation;
using redb.Identity.Contracts.Groups;
using redb.Identity.Contracts.Mfa;
using redb.Identity.Contracts.Sessions;
using redb.Identity.Contracts.SigningKeys;
using redb.Identity.Contracts.Tokens;
using redb.Identity.Contracts.Users;
using redb.Identity.Contracts.Validation;
using redb.Identity.Contracts.Webhooks;
using Xunit;
namespace redb.Identity.Tests.Management;
///
/// Each result type next to the anonymous object or dictionary its route answered with before, as that route built it,
/// written under every option set the answer can be serialized with: the HTTP and gRPC controller dispatchers,
/// the serializer defaults, and the ASP.NET Core web defaults the Web host answers with. The bytes must be equal.
/// This covers the routes no wire test reaches: the self-service ones a user token calls, the cleanup routes a
/// timer runs, the signing key retirement that would change the keys of the test host, and the rare branches.
///
public class ResultContractsParityTests
{
private static readonly JsonSerializerOptions HttpDispatcher = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};
private static readonly JsonSerializerOptions GrpcDispatcher = new() { PropertyNameCaseInsensitive = true };
private static readonly JsonSerializerOptions WebDefaults = new(JsonSerializerDefaults.Web);
private static readonly JsonSerializerOptions Defaults = new();
private static readonly DateTimeOffset Created = new(2026, 11, 17, 10, 0, 0, TimeSpan.Zero);
private static readonly DateTimeOffset Modified = new(2026, 11, 17, 11, 30, 0, TimeSpan.FromHours(1));
private static readonly JsonElement WebAuthnOptions = JsonSerializer.SerializeToElement(new Dictionary
{
["rp"] = new Dictionary { ["id"] = "localhost", ["name"] = "redb" },
["challenge"] = "AAECAw",
["pubKeyCredParams"] = new[] { new Dictionary { ["type"] = "public-key", ["alg"] = -7 } },
});
private static readonly Dictionary Cases = new()
{
["group"] = (
new { id = 7L, name = (string?)"g", parentId = (long?)null, groupType = (string?)null, description = (string?)"d", createdAt = Created, modifiedAt = Modified },
new GroupResponse { Id = 7, Name = "g", ParentId = null, GroupType = null, Description = "d", CreatedAt = Created, ModifiedAt = Modified }),
["group with members"] = (
new { id = 7L, name = (string?)"g", parentId = (long?)3, groupType = (string?)"team", description = (string?)null, createdAt = Created, modifiedAt = Modified, memberCount = 2 },
new GroupResponse { Id = 7, Name = "g", ParentId = 3, GroupType = "team", Description = null, CreatedAt = Created, ModifiedAt = Modified, MemberCount = 2 }),
["group tree"] = (
new
{
id = 1L, name = (string?)"root", parentId = (long?)null, groupType = (string?)null, description = (string?)null, level = 0,
children = new List