Path: redb-route/tests/redb.Route.Tests.As2/As2RestartTests.cs Snapshot: redb-route, 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-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.As2/As2RestartTests.cs ---- using System.Text; using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.As2; using redb.Route.Core; using As2Dsl = redb.Route.As2.Fluent.As2; namespace redb.Route.Tests.As2; /// /// An AS2 consumer and producer keep working after Stop() and Start() of the same route context: the stop /// gives the listener path back, the start registers it again on the cached endpoint, and a message is signed, /// encrypted, received and acknowledged with an MDN on both runs. /// public class As2RestartTests { [Fact] public async Task Consumer_and_producer_work_after_the_context_is_stopped_and_started_again() { var port = As2TestKit.FreePort(); await using var context = new RouteContext(); context.AddComponent(new As2Component()); context.AddToRegistry("me", As2TestKit.Receiver()); context.AddToRegistry("them", As2TestKit.Sender()); var received = new List(); context.AddRoutes(r => r.From(As2Dsl.Receive("/inbound").Host("127.0.0.1").Port(port).ConnectionFactory("me")) .Process(e => { lock (received) received.Add(Encoding.UTF8.GetString((byte[])e.In.Body!)); })); context.AddRoutes(r => r.From("direct://send").To(As2Dsl.Send($"http://127.0.0.1:{port}/inbound").ConnectionFactory("them"))); async Task SendAsync(string payload) { var producer = context.GetEndpoint("direct://send").CreateProducer(); await producer.Start(); var exchange = new Exchange(new Message(payload) { ContentType = "application/edi-x12" }); await producer.Process(exchange); exchange.Exception.Should().BeNull("an AS2 send after a restart arrives and gets an MDN"); } await context.Start(); await SendAsync("ISA*first~"); await context.Stop(); await context.Start(); await SendAsync("ISA*second~"); lock (received) received.Should().Equal(["ISA*first~", "ISA*second~"], "the AS2 receiver accepts after a restart"); } }