Path: redb-identity/tests/redb.Identity.Tests/FullStack/ManagementConflictStatusTests.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/FullStack/ManagementConflictStatusTests.cs ---- using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; using AwesomeAssertions; using redb.Identity.Core.Services; using redb.Identity.Tests.Infrastructure; using Xunit; using Xunit.Abstractions; namespace redb.Identity.Tests.FullStack; /// /// A request that is well formed but cannot be carried out against the current state is a conflict /// and is answered 409 on every management endpoint; a record that does not exist is 404. Neither is /// the 400 of a malformed request. /// [Collection("ProductionHttp")] public class ManagementConflictStatusTests { private readonly ProductionHttpFixture _fx; private readonly ITestOutputHelper _out; public ManagementConflictStatusTests(ProductionHttpFixture fx, ITestOutputHelper output) { _fx = fx; _out = output; } [Fact] public async Task Role_SecondCreateOfTheSameName_Answers409() { var body = new { name = "conflict-role-" + Guid.NewGuid().ToString("N")[..12], audience = "organization" }; using var first = await SendAsync(HttpMethod.Post, "/api/v1/identity/roles", body); ((int)first.StatusCode).Should().BeInRange(200, 299, await first.Content.ReadAsStringAsync()); using var second = await SendAsync(HttpMethod.Post, "/api/v1/identity/roles", body); ((int)second.StatusCode).Should().Be(409, await second.Content.ReadAsStringAsync()); } [Fact] public async Task Role_DeleteOfARoleThatDoesNotExist_Answers404() { using var response = await SendAsync(HttpMethod.Delete, "/api/v1/identity/roles/987654321012", body: null); ((int)response.StatusCode).Should().Be(404, await response.Content.ReadAsStringAsync()); } [Fact] public async Task Role_DeleteOfASystemRole_Answers409() { var name = "conflict-system-role-" + Guid.NewGuid().ToString("N")[..12]; var roleId = await _fx.UseRedbAsync(async redb => { var role = await new RoleService(redb).CreateRoleAsync( name, "organization", applicationId: null, displayName: null, description: null, isSystem: true); return role.Id; }); using var response = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/roles/{roleId}", body: null); ((int)response.StatusCode).Should().Be(409, await response.Content.ReadAsStringAsync()); } [Fact] public async Task ClaimDefinition_SecondCreateOfTheSameClaim_Answers409() { var body = new { claimName = "conflict_claim_" + Guid.NewGuid().ToString("N")[..12], scope = "global", type = "string", required = false, }; using var first = await SendAsync(HttpMethod.Post, "/api/v1/identity/claim-definitions", body); var created = await first.Content.ReadAsStringAsync(); ((int)first.StatusCode).Should().BeInRange(200, 299, created); try { using var second = await SendAsync(HttpMethod.Post, "/api/v1/identity/claim-definitions", body); ((int)second.StatusCode).Should().Be(409, await second.Content.ReadAsStringAsync()); } finally { // A global definition takes part in every registration of the fixture: remove it. using var json = JsonDocument.Parse(created); if (json.RootElement.TryGetProperty("id", out var id)) { using var removed = await SendAsync(HttpMethod.Delete, $"/api/v1/identity/claim-definitions/{id}", body: null); } } } private Task SendAsync(HttpMethod method, string path, object? body) { var request = new HttpRequestMessage(method, path); if (body is not null) request.Content = JsonContent.Create(body); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _fx.ManagementToken); return _fx.Http.SendAsync(request); } }