Path: redb-route/tests/redb.Route.Tests/Xslt/XsltIntegrationTests.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/Xslt/XsltIntegrationTests.cs ---- using AwesomeAssertions; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Xslt; namespace redb.Route.Tests.Xslt; /// /// Integration tests for XSLT through the DSL → Compiler → Engine pipeline, covering the inline /// .XsltContent(...) and file-based .Xslt(...) leaf forms and the xslt: component. /// public class XsltIntegrationTests : IAsyncLifetime { private const string Stylesheet = """ """; // Alternate stylesheet used for the dynamic (from-header) test: greeting → . private const string AltStylesheet = """ """; // Stylesheet that reads a parameter fed from a message header. private const string ParamStylesheet = """ region= """; private const string Input = "world"; private const string Expected = "world"; private readonly RouteContext _context = new(); private readonly string _stylesheetFile; private readonly string _altStylesheetFile; public XsltIntegrationTests() { _stylesheetFile = Path.Combine(Path.GetTempPath(), $"redb-xslt-{Guid.NewGuid():N}.xsl"); File.WriteAllText(_stylesheetFile, Stylesheet); _altStylesheetFile = Path.Combine(Path.GetTempPath(), $"redb-xslt-alt-{Guid.NewGuid():N}.xsl"); File.WriteAllText(_altStylesheetFile, AltStylesheet); } public Task InitializeAsync() => Task.CompletedTask; public async Task DisposeAsync() { await _context.DisposeAsync(); try { File.Delete(_stylesheetFile); } catch { /* best-effort */ } try { File.Delete(_altStylesheetFile); } catch { /* best-effort */ } GC.SuppressFinalize(this); } private async Task StartAndGetProducer(string fromUri) { await _context.Start(); var producer = _context.GetEndpoint(fromUri).CreateProducer(); await producer.Start(); return producer; } [Fact] public async Task Xslt_InlineContent_TransformsBody() { object? result = null; _context.AddRoutes(r => r.From("direct://xslt-content") .XsltContent(Stylesheet) .Process(e => result = e.In.Body)); var producer = await StartAndGetProducer("direct://xslt-content"); await producer.Process(new Exchange(new Message(Input))); result.Should().Be(Expected); } [Fact] public async Task Xslt_FromFile_TransformsBody() { object? result = null; _context.AddRoutes(r => r.From("direct://xslt-file") .Xslt(_stylesheetFile) .Process(e => result = e.In.Body)); var producer = await StartAndGetProducer("direct://xslt-file"); await producer.Process(new Exchange(new Message(Input))); result.Should().Be(Expected); } [Fact] public async Task Xslt_Component_ViaTo_TransformsBody() { // The xslt: component is registered out of the box — no AddComponent needed. object? result = null; _context.AddRoutes(r => r.From("direct://xslt-comp") .To($"xslt:{_stylesheetFile}") .Process(e => result = e.In.Body)); var producer = await StartAndGetProducer("direct://xslt-comp"); await producer.Process(new Exchange(new Message(Input))); result.Should().Be(Expected); } [Fact] public async Task Xslt_Component_BytesOutput() { object? result = null; _context.AddRoutes(r => r.From("direct://xslt-bytes") .To($"xslt:{_stylesheetFile}?output=bytes") .Process(e => result = e.In.Body)); var producer = await StartAndGetProducer("direct://xslt-bytes"); await producer.Process(new Exchange(new Message(Input))); result.Should().BeOfType(); System.Text.Encoding.UTF8.GetString((byte[])result!).Should().Contain(Expected); } [Fact] public async Task Xslt_PassesHeadersAsParameters() { object? result = null; _context.AddRoutes(r => r.From("direct://xslt-param") .XsltContent(ParamStylesheet) .Process(e => result = e.In.Body)); var producer = await StartAndGetProducer("direct://xslt-param"); var exchange = new Exchange(new Message("")); exchange.In.Headers["region"] = "EU"; // fed to await producer.Process(exchange); result.Should().Be("region=EU"); } [Fact] public async Task Xslt_AllowTemplateFromHeader_OverridesStylesheetPerMessage() { object? result = null; _context.AddRoutes(r => r.From("direct://xslt-dyn") .Xslt(_stylesheetFile, allowTemplateFromHeader: true) // default → .Process(e => result = e.In.Body)); var producer = await StartAndGetProducer("direct://xslt-dyn"); var exchange = new Exchange(new Message(Input)); exchange.In.Headers[XsltHeaders.ResourceUri] = _altStylesheetFile; // override → await producer.Process(exchange); result.Should().Be("world"); } }