Path: redb-route/tests/redb.Route.Tests.Sql/Batch/BatchItemFrameworkTypeTests.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.Sql/Batch/BatchItemFrameworkTypeTests.cs ---- using System.Text.Json; using System.Xml.Linq; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Tests.Sql.E2E.Infrastructure; namespace redb.Route.Tests.Sql.Batch; /// /// Batch items whose type comes from .NET itself are not POCOs: their properties are not record fields. An XML node carries no /// named values, as in Apache Camel — its values are bound with xpath expressions; a JSON document is read as its JSON. /// public sealed class BatchItemFrameworkTypeTests : IDisposable { private readonly SqliteTestHelper _db = new(); public BatchItemFrameworkTypeTests() => _db.Execute("CREATE TABLE framework_items (id INTEGER NULL, val TEXT NULL)"); public void Dispose() => _db.Dispose(); [Fact] public async Task Binder_XElementItems_NamedPlaceholder_FailsWithXPathHint() { var items = new List { XElement.Parse("""n1text""") }; var thrown = await RunAsync("INSERT INTO framework_items (id, val) VALUES (:#id, :#value)", items, new() { ["param.id"] = "1" }); thrown.Should().BeOfType( $"XElement.Value is not a field named 'value' ({Outcome.Describe(thrown)}, rows: {string.Join(", ", Rows())})") .Which.Message.Should().Contain("item 0").And.Contain(":#value").And.Contain("xpath"); Rows().Should().BeEmpty(); } [Fact] public async Task Binder_XElementItems_BindWithXPathExpressions() { var items = new List { XElement.Parse("""n1"""), XElement.Parse("""n2"""), }; var thrown = await RunAsync("INSERT INTO framework_items (id, val) VALUES (:#id, :#val)", items, new() { ["param.id"] = "${xpath('@id')}", ["param.val"] = "${xpath('name')}", }); thrown.Should().BeNull(Outcome.Describe(thrown)); Rows().Should().Equal("1|n1", "2|n2"); } [Fact] public async Task Binder_JsonDocumentItems_BindByKeys() { using var first = JsonDocument.Parse("""{"id":1,"val":"a"}"""); using var second = JsonDocument.Parse("""{"id":2,"val":null}"""); var thrown = await RunAsync("INSERT INTO framework_items (id, val) VALUES (:#id, :#val)", new List { first, second }); thrown.Should().BeNull(Outcome.Describe(thrown)); Rows().Should().Equal("1|a", "2|"); } [Fact] public async Task Binder_FrameworkObjectItem_HasNoNamedValues() { var items = new List { new Uri("https://h.example:8443/p") }; var thrown = await RunAsync("INSERT INTO framework_items (id, val) VALUES (:#port, :#host)", items); thrown.Should().BeOfType( $"Uri.Port and Uri.Host are not record fields ({Outcome.Describe(thrown)}, rows: {string.Join(", ", Rows())})") .Which.Message.Should().Contain("item 0").And.Contain(":#port"); Rows().Should().BeEmpty(); } [Fact] public async Task Binder_AnonymousTypeItems_BindByProperty() { var items = new List { new { id = 1, val = "a" }, new { id = 2, val = (string?)null } }; var thrown = await RunAsync("INSERT INTO framework_items (id, val) VALUES (:#id, :#val)", items); thrown.Should().BeNull(Outcome.Describe(thrown)); Rows().Should().Equal("1|a", "2|"); } private async Task RunAsync(string sql, object items, Dictionary? options = null) { var parameters = new Dictionary { ["outputType"] = "None", ["batchSize"] = "10" }; if (options is not null) foreach (var (key, value) in options) parameters[key] = value; await using var context = new RouteContext(); var endpoint = SqlEndpointHarness.CreateEndpoint(context, _db.CreateFactory(), sql, parameters); IExchange carrier = new Exchange(new Message(items)); return await Outcome.Of(() => endpoint.CreateProducer().Process(carrier, CancellationToken.None)); } private List Rows() => _db.Query("SELECT id, val FROM framework_items ORDER BY id").Select(r => $"{r["id"]}|{r["val"]}").ToList(); }