Path: redb-identity/tests/redb.Identity.Tests/Pipeline/EventPipelineTests.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/EventPipelineTests.cs ---- using AwesomeAssertions; using NSubstitute; using redb.Core.Models.Entities; using redb.Identity.Contracts.Applications; using redb.Identity.Contracts.Events; using redb.Identity.Contracts.Scopes; using redb.Identity.Core.Models; using redb.Identity.Contracts.Routes; using redb.Identity.Tests.Infrastructure; using redb.Route.Core; using Xunit; namespace redb.Identity.Tests.Pipeline; /// /// Tests that WireTap event dispatch actually fires through the pipeline. /// Creates a second consumer on the Events endpoint to capture dispatched events. /// [Collection("IdentityRoute")] public class EventPipelineTests { private readonly IdentityRouteFixture _fixture; public EventPipelineTests(IdentityRouteFixture fixture) => _fixture = fixture; [Fact] public async Task CreateApp_WireTap_DispatchesClientRegisteredEvent() { MockRedbQuery.Setup(_fixture.Redb, new List>()); _fixture.Redb.SaveAsync(Arg.Any>()) .Returns(ci => { ci.Arg>().Id = 200; return 200L; }); var exchange = await _fixture.RequestWithHeaders( IdentityEndpoints.ManageApps, new CreateApplicationRequest { ClientId = "event-test-app", ClientSecret = "secret", ClientType = "confidential" }, new Dictionary { ["operation"] = "create" }); exchange.Exception.Should().BeNull(); // The WireTap copies exchange properties to the event route. // Verify the original exchange has the event metadata set by the processor. exchange.Properties.Should().ContainKey("identity-event-type"); exchange.Properties["identity-event-type"].Should().Be("ClientRegistered"); } [Fact] public async Task CreateScope_WireTap_DispatchesScopeCreatedEvent() { MockRedbQuery.Setup(_fixture.Redb, new List>()); _fixture.Redb.SaveAsync(Arg.Any>()) .Returns(ci => { ci.Arg>().Id = 201; return 201L; }); var exchange = await _fixture.RequestWithHeaders( IdentityEndpoints.ManageScopes, new CreateScopeRequest { Name = "event-scope", DisplayName = "Event Scope" }, new Dictionary { ["operation"] = "create" }); exchange.Exception.Should().BeNull(); exchange.Properties.Should().ContainKey("identity-event-type"); exchange.Properties["identity-event-type"].Should().Be("ScopeCreated"); } [Fact] public async Task TokenIssuance_Success_DispatchesTokenIssuedEvent() { var body = new Dictionary { ["grant_type"] = "client_credentials", ["client_id"] = "event-token-client", ["client_secret"] = "secret" }; var exchange = await _fixture.RequestWithHeaders( IdentityEndpoints.Token, body, new Dictionary()); exchange.Exception.Should().BeNull(); var dict = exchange.In.Body.Should().BeOfType>().Subject; dict.Should().ContainKey("access_token"); // TokenEndpointProcessor sets event on success exchange.Properties.Should().ContainKey("identity-event-type"); exchange.Properties["identity-event-type"].Should().Be("TokenIssued"); } [Fact] public async Task TokenIssuance_Failure_DoesNotDispatchEvent() { var body = new Dictionary { ["grant_type"] = "client_credentials" // missing client_id → will fail }; var exchange = await _fixture.RequestWithHeaders( IdentityEndpoints.Token, body, new Dictionary()); // On error, TokenEndpointProcessor should NOT set event (fix #5) exchange.Properties.Should().NotContainKey("identity-event-type"); } [Fact] public async Task DeleteApp_WireTap_DispatchesClientDeletedEvent() { // The delete looks the record up first; it exists and is of this resource. _fixture.Redb.LoadAsync(300).Returns(new RedbObject(new ApplicationProps()) { id = 300 }); _fixture.Redb.DeleteAsync(300).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"] = 300L }, new Dictionary { ["operation"] = "delete" }); exchange.Exception.Should().BeNull(); exchange.Properties.Should().ContainKey("identity-event-type"); exchange.Properties["identity-event-type"].Should().Be("ClientDeleted"); } }