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