Bundle: redb-route / tests/redb.Route.Tests.JsonTransform (tests.redb.Route.Tests.JsonTransform.txt), 5 files Snapshot: 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 Index: https://redbase.app/src/dev-2026-12-06/redb-route/_index.txt ==== Path: redb-route/tests/redb.Route.Tests.JsonTransform/JsonTransformCacheKeyTests.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.JsonTransform/JsonTransformCacheKeyTests.cs ---- using redb.Route.Core; using redb.Route.JsonTransform; using redb.Route.TestKit; namespace redb.Route.Tests.JsonTransform; /// Code review 2026-09-01: the specification cache is keyed by the resolved file, not by the relative name. public class JsonTransformCacheKeyTests { [Fact] public async Task CompileCache_IsKeyedByTheResolvedFile_NotByTheRelativeName() { var a = Directory.CreateTempSubdirectory("redb-jsonata-a-"); var b = Directory.CreateTempSubdirectory("redb-jsonata-b-"); try { await System.IO.File.WriteAllTextAsync(Path.Combine(a.FullName, "s.jsonata"), "\"FROM-A\""); await System.IO.File.WriteAllTextAsync(Path.Combine(b.FullName, "s.jsonata"), "\"FROM-B\""); (await TransformFrom(a.FullName)).Should().Be("\"FROM-A\""); (await TransformFrom(b.FullName)).Should().Be("\"FROM-B\"", "a different base directory is a different specification"); await System.IO.File.WriteAllTextAsync(Path.Combine(a.FullName, "s.jsonata"), "\"EDITED-A\""); (await TransformFrom(a.FullName)).Should().Be("\"EDITED-A\"", "a new context compiles the edited file afresh"); } finally { a.Delete(recursive: true); b.Delete(recursive: true); } static async Task TransformFrom(string baseDirectory) { await using var ctx = new RouteContext(); ctx.UseJsonTransform(o => o.BaseDirectory = baseDirectory); ctx.AddRoutes(r => r.From("direct://k").TransformJson("s.jsonata")); await ctx.Start(); return await ctx.RequestBody("direct://k", "{}"); } } } Path: redb-route/tests/redb.Route.Tests.JsonTransform/JsonTransformResourceResolverTests.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.JsonTransform/JsonTransformResourceResolverTests.cs ---- using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.JsonTransform; using redb.Route.TestKit; namespace redb.Route.Tests.JsonTransform; /// /// A JSONata specification named by a relative path follows the same lookup as every other file /// reference: the context's first, then the package's base /// directory. Same report as the templates one (Route-XML agent, 2026-09-24): inside a /// .tpkg the specification lives in resources/, which only the resolver knows. /// public class JsonTransformResourceResolverTests { private sealed class RootResolver(string root) : IRouteResourceResolver { public string? Resolve(string reference) { if (Path.IsPathRooted(reference)) return System.IO.File.Exists(reference) ? reference : null; var candidate = Path.GetFullPath(Path.Combine(root, reference)); return System.IO.File.Exists(candidate) ? candidate : null; } public string DescribeSearch(string reference) => Path.Combine(root, reference); } private static async Task Transform(string root, string relativePath, object? body) { await using var ctx = new RouteContext(); ctx.AddService(typeof(IRouteResourceResolver), new RootResolver(root)); ctx.AddRoutes(r => r.From("direct://jres").TransformJson(relativePath)); await ctx.Start(); return await ctx.RequestBody("direct://jres", body); } [Fact] public async Task A_specification_the_resolver_knows_is_found_although_the_base_directory_does_not_hold_it() { var pkg = Directory.CreateTempSubdirectory("redb-jt-pkg-"); try { Directory.CreateDirectory(Path.Combine(pkg.FullName, "specs")); await System.IO.File.WriteAllTextAsync(Path.Combine(pkg.FullName, "specs", "order.jsonata"), "orderId"); var result = await Transform(pkg.FullName, "specs/order.jsonata", """{"orderId":"A-1"}"""); result.Should().Be("\"A-1\""); } finally { pkg.Delete(recursive: true); } } [Fact] public async Task Two_resolvers_with_one_relative_name_are_two_specifications() { var a = Directory.CreateTempSubdirectory("redb-jt-ra-"); var b = Directory.CreateTempSubdirectory("redb-jt-rb-"); try { await System.IO.File.WriteAllTextAsync(Path.Combine(a.FullName, "s.jsonata"), "a"); await System.IO.File.WriteAllTextAsync(Path.Combine(b.FullName, "s.jsonata"), "b"); (await Transform(a.FullName, "s.jsonata", """{"a":1,"b":2}""")).Should().Be("1"); (await Transform(b.FullName, "s.jsonata", """{"a":1,"b":2}""")).Should().Be("2"); } finally { a.Delete(recursive: true); b.Delete(recursive: true); } } [Fact] public async Task A_specification_in_neither_place_names_both_of_them() { var resolverRoot = Directory.CreateTempSubdirectory("redb-jt-nr-"); var baseDir = Directory.CreateTempSubdirectory("redb-jt-nb-"); try { await using var ctx = new RouteContext(); ctx.AddService(typeof(IRouteResourceResolver), new RootResolver(resolverRoot.FullName)); ctx.UseJsonTransform(o => o.BaseDirectory = baseDir.FullName); ctx.AddRoutes(r => r.From("direct://jmissing").TransformJson("nowhere.jsonata")); var act = () => ctx.Start(); (await act.Should().ThrowAsync()).Which.ToString() .Should().Contain(resolverRoot.FullName).And.Contain(baseDir.FullName); } finally { resolverRoot.Delete(recursive: true); baseDir.Delete(recursive: true); } } } Path: redb-route/tests/redb.Route.Tests.JsonTransform/JsonTransformReviewTests.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.JsonTransform/JsonTransformReviewTests.cs ---- using redb.Route.Core; using redb.Route.JsonTransform; using redb.Route.TestKit; namespace redb.Route.Tests.JsonTransform; /// Code review 2026-09-01, fourth batch: stream input, error naming, content type of the result. public class JsonTransformReviewTests { [Fact] public async Task StreamBody_IsReadFromItsPosition_AndLeftThere() { await using var ctx = new RouteContext().AddRoutes(b => b .From("direct://stream").TransformJson(TextSource.Inline("orderId"), JsonTransformOutput.String).To("mock://stream")); await ctx.Start(); var stream = new MemoryStream("""{"orderId": 7}"""u8.ToArray()); await ctx.SendBody("direct://stream", stream); ctx.Mock("mock://stream").ReceivedExchanges[0].In.Body.Should().BeOfType().Which.Should().Be("7"); stream.CanRead.Should().BeTrue("the stream belongs to the exchange, the step must not close it"); stream.Position.Should().Be(0, "a later step may need to read the stream too"); } [Fact] public async Task ANonJsonBody_FailsWithTheSpecificationName() { await using var ctx = new RouteContext().AddRoutes(b => b .From("direct://bad").TransformJson(TextSource.Inline("orderId"))); await ctx.Start(); var act = () => ctx.SendBody("direct://bad", "not json at all"); await act.Should().ThrowAsync().WithMessage("**not JSON*"); } [Fact] public async Task NodeOutput_CarriesTheJsonContentType() { await using var ctx = new RouteContext().AddRoutes(b => b .From("direct://node") .Process(e => e.In.ContentType = "text/plain") .TransformJson(TextSource.Inline("$"), JsonTransformOutput.Node) .To("mock://node")); await ctx.Start(); await ctx.SendBody("direct://node", """{"a":1}"""); ctx.Mock("mock://node").ReceivedExchanges[0].In.ContentType.Should().Be("application/json"); } } Path: redb-route/tests/redb.Route.Tests.JsonTransform/JsonTransformTests.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.JsonTransform/JsonTransformTests.cs ---- using System.Text.Json; using System.Text.Json.Nodes; using redb.Route.Core; using redb.Route.JsonTransform; using redb.Route.TestKit; using static redb.Route.Core.TextSource; namespace redb.Route.Tests.JsonTransform; public class JsonTransformTests { private const string Order = """ {"orderId": 7, "address": {"city": "Kazan", "zip": "420000"}, "items": [{"sku": "a", "qty": 2, "price": 1.5}, {"sku": "b", "qty": 1, "price": 10}]} """; private static async Task Run(TextSource spec, object? body, JsonTransformOutput output = JsonTransformOutput.String, IDictionary? headers = null, Action? options = null) { await using var ctx = new RouteContext(); if (options is not null) ctx.UseJsonTransform(options); ctx.AddRoutes(b => b.From("direct://in").TransformJson(spec, output).To("mock://out")); await ctx.Start(); await ctx.SendBodyAndHeaders("direct://in", body, headers ?? new Dictionary()); return ctx.Mock("mock://out").ReceivedExchanges[0].In.Body; } private static JsonElement Json(object? body) => JsonDocument.Parse((string)body!).RootElement; [Fact] public async Task Rename_Nest_UnwrapArray_Default_FromFile() { var result = Json(await Run(File("Transforms/order-to-shipment.jsonata"), Order)); result.GetProperty("id").GetInt32().Should().Be(7); result.GetProperty("to").GetProperty("city").GetString().Should().Be("Kazan"); result.GetProperty("skus").EnumerateArray().Select(e => e.GetString()).Should().Equal("a", "b"); result.GetProperty("total").GetDecimal().Should().Be(13m); result.GetProperty("status").GetString().Should().Be("new", "the default applies when the field is missing"); } [Fact] public async Task Output_IsJsonText_WithContentType() { await using var ctx = new RouteContext().AddRoutes(b => b .From("direct://ct").TransformJson(Inline("{ \"id\": orderId }")).To("mock://ct")); await ctx.Start(); await ctx.SendBody("direct://ct", Order); var message = ctx.Mock("mock://ct").ReceivedExchanges[0].In; message.Body.Should().Be("""{"id":7}"""); message.ContentType.Should().Be("application/json"); } [Fact] public async Task HeadersAndProperties_AreBound() { await using var ctx = new RouteContext().AddRoutes(b => b .From("direct://bind") .SetProperty("region", "eu") .TransformJson(Inline("{ \"tenant\": $headers.tenant, \"region\": $properties.region, \"id\": orderId }")) .To("mock://bind")); await ctx.Start(); await ctx.SendBodyAndHeader("direct://bind", Order, "tenant", "acme"); var result = Json(ctx.Mock("mock://bind").ReceivedExchanges[0].In.Body); result.GetProperty("tenant").GetString().Should().Be("acme"); result.GetProperty("region").GetString().Should().Be("eu"); result.GetProperty("id").GetInt32().Should().Be(7); } [Fact] public async Task Input_Poco_Bytes_And_JsonNode() { var spec = Inline("{ \"city\": address.city }"); Json(await Run(spec, new { address = new { city = "Ufa" } })).GetProperty("city").GetString().Should().Be("Ufa"); Json(await Run(spec, "{\"address\":{\"city\":\"Perm\"}}"u8.ToArray())).GetProperty("city").GetString().Should().Be("Perm"); Json(await Run(spec, JsonNode.Parse("{\"address\":{\"city\":\"Omsk\"}}"))).GetProperty("city").GetString().Should().Be("Omsk"); } [Fact] public async Task NodeOutput_LeavesAJsonNodeBody() { var body = await Run(Inline("{ \"id\": orderId }"), Order, JsonTransformOutput.Node); body.Should().BeAssignableTo().Which["id"]!.GetValue().Should().Be(7, "JSONata integers arrive as Int64"); } [Fact] public async Task UndefinedResult_IsNullBody() { (await Run(Inline("nothing.here"), Order)).Should().BeNull(); } [Fact] public async Task Indent_Option() { var body = (string)(await Run(Inline("{ \"id\": orderId }"), Order, options: o => o.Indent = true))!; body.Should().Contain("\n"); Json(body).GetProperty("id").GetInt32().Should().Be(7); } [Fact] public async Task BadSpecification_FailsStart_WithName() { await using var ctx = new RouteContext().AddRoutes(b => b.From("direct://bad").TransformJson(Inline("{ \"id\": "))); var act = () => ctx.Start(); var ex = await act.Should().ThrowAsync(); ex.Which.SpecificationName.Should().Be(""); ex.Which.Message.Should().StartWith("JSON transform '':"); } [Fact] public async Task MissingFile_FailsStart_WithLocator() { await using var ctx = new RouteContext().AddRoutes(b => b.From("direct://nf").TransformJson("Transforms/nope.jsonata")); var act = () => ctx.Start(); (await act.Should().ThrowAsync()).Which.Message.Should().Contain("Transforms/nope.jsonata").And.Contain("not found"); } [Fact] public async Task InvalidJsonBody_FailsTheMessage_NotStart() { await using var ctx = new RouteContext().AddRoutes(b => b.From("direct://badbody").TransformJson(Inline("{ \"id\": orderId }"))); await ctx.Start(); var act = () => ctx.SendBody("direct://badbody", "not json"); await act.Should().ThrowAsync(); } [Fact] public void Cache_SameSource_CompilesOnce() { var options = new JsonTransformOptions(); var first = JsonTransformEngine.Compile(File("Transforms/order-to-shipment.jsonata"), options); var second = JsonTransformEngine.Compile(File("Transforms/order-to-shipment.jsonata"), options); second.Should().BeSameAs(first); } [Fact] public async Task AbsolutePath_And_BaseDirectoryOption() { var dir = Directory.CreateTempSubdirectory("redb-jsonata-"); try { var path = Path.Combine(dir.FullName, "t.jsonata"); await System.IO.File.WriteAllTextAsync(path, "{ \"n\": $count(items) }"); Json(await Run(File(path), Order)).GetProperty("n").GetInt32().Should().Be(2); Json(await Run(File("t.jsonata"), Order, options: o => o.BaseDirectory = dir.FullName)).GetProperty("n").GetInt32().Should().Be(2); } finally { dir.Delete(recursive: true); } } } Path: redb-route/tests/redb.Route.Tests.JsonTransform/redb.Route.Tests.JsonTransform.csproj 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.JsonTransform/redb.Route.Tests.JsonTransform.csproj ----