Path: redb-route/tests/redb.Route.Tests.Soap/SoapInteropTests.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.Soap/SoapInteropTests.cs
----
using System.Diagnostics;
using System.Net.Sockets;
using System.Xml.Linq;
using AwesomeAssertions;
using redb.Route.Abstractions;
using redb.Route.Core;
using SoapDsl = redb.Route.Soap.Fluent.Soap;
namespace redb.Route.Tests.Soap;
///
/// Live interop against an independent SOAP stack — the Node.js soap library, a mature
/// implementation with no shared code with this connector (profile soap of docker-compose.tests.yml). This proves what
/// loopback e2e cannot: that a foreign SOAP implementation accepts our on-the-wire envelope, and that we
/// accept its. CoreWCF was rejected as the reference stack because every version carries an unpatched
/// crypto CVE; a JVM/CXF image is heavier but equivalent — Node was chosen only because its base image was
/// already cached. GATED: each test no-ops unless the container answers on 127.0.0.1:18060, so the normal
/// suite stays green without it. Run with --filter Category=Interop after
/// docker compose -f redb.Route/docker-compose.tests.yml --profile soap up -d --wait.
///
[Trait("Category", "Interop")]
public class SoapInteropTests
{
private const string Host = "127.0.0.1";
private const int ServerPort = 18060; // Node SOAP echo server (compose port mapping)
// Our consumer; the container reaches it via host-gateway. Offset by runtime major so the parallel
// multi-TFM test hosts never contend for the same port.
// 18160+: clear of the gRPC interop ports (18100 and 18110-18159).
private static readonly int ConsumerPort = 18160 + Environment.Version.Major;
private static string ServerUrl => $"http://{Host}:{ServerPort}/echo";
/// Direction A: our producer → the independent Node SOAP server. Proves a foreign stack accepts our wire.
[Fact]
public async Task Redb_Producer_To_NodeSoapServer_Echoes()
{
if (!IsReachable(Host, ServerPort))
return; // gated: Node SOAP server not running — profile soap of docker-compose.tests.yml
await using var ctx = new RouteContext();
ctx.AddComponent(new redb.Route.Soap.SoapComponent());
ctx.AddRoutes(r => r.From("direct://call")
.To(SoapDsl.Call(ServerUrl).Action("urn:soaptest/Echo")));
await ctx.Start();
var producer = ctx.GetEndpoint("direct://call").CreateProducer();
await producer.Start();
var exchange = new Exchange(new Message(
"hello-redb"));
await producer.Process(exchange);
// The Node service parsed our envelope, ran Echo, and returned a response our parser read back.
exchange.HasOut.Should().BeTrue();
var result = XElement.Parse(exchange.Out!.Body!.ToString()!)
.Descendants().First(x => x.Name.LocalName == "result").Value;
result.Should().Be("echo:hello-redb");
}
/// Direction B: the independent Node SOAP client → our consumer. Proves a foreign client accepts our responses.
[Fact]
public async Task NodeSoapClient_To_RedbConsumer_Echoes()
{
if (!IsReachable(Host, ServerPort))
return; // gated: Node SOAP container not running
await using var ctx = new RouteContext();
ctx.AddComponent(new redb.Route.Soap.SoapComponent());
// Bind on all interfaces so the container's host-gateway can reach us.
ctx.AddRoutes(r => r.From(SoapDsl.Listen("/svc").Host("0.0.0.0").Port(ConsumerPort))
.Process(e =>
{
var msg = XElement.Parse(e.In.Body!.ToString()!)
.Descendants().First(x => x.Name.LocalName == "msg").Value;
// Match the WSDL response shape (EchoResponse qualified, result unqualified) so the Node client parses it.
e.In.Body = $"redb:{msg}";
}));
await ctx.Start();
var (stdout, stderr, exit) = RunNodeClient("hi-from-node");
exit.Should().Be(0, $"node client should succeed; stderr='{stderr}'");
stdout.Should().Contain("RESULT:redb:hi-from-node");
}
private static (string stdout, string stderr, int exit) RunNodeClient(string msg)
{
var psi = new ProcessStartInfo("docker")
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
};
psi.ArgumentList.Add("exec");
psi.ArgumentList.Add("soap-echo");
psi.ArgumentList.Add("sh");
psi.ArgumentList.Add("-c");
psi.ArgumentList.Add($"TARGET=http://host.docker.internal:{ConsumerPort}/svc node /app/client.js {msg}");
using var p = Process.Start(psi)!;
var stdout = p.StandardOutput.ReadToEnd();
var stderr = p.StandardError.ReadToEnd();
p.WaitForExit(15000);
return (stdout, stderr, p.HasExited ? p.ExitCode : -1);
}
private static bool IsReachable(string host, int port)
{
try
{
using var client = new TcpClient();
var connect = client.ConnectAsync(host, port);
return connect.Wait(TimeSpan.FromMilliseconds(500)) && client.Connected;
}
catch
{
return false;
}
}
}