Path: redb-route/tests/redb.Route.Tests.Core/Integration/RedbQueryConstantInsideOrIntegrationTests.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.Core/Integration/RedbQueryConstantInsideOrIntegrationTests.cs
----
using redb.Core;
using redb.Core.Models.Entities;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.RedbCore.Extensions;
namespace redb.Route.Tests.Core.Integration;
///
/// An empty list in a redbQuery where-string against a real Pro database. The translator decides
/// x in <empty> as the constant false and x not in <empty> as the constant true, so
/// next to OR and AND the storage receives a constant inside a logical node. The rows must be those LINQ gives:
/// in <empty> OR cond is the rows of cond, not in <empty> OR cond is every row,
/// in <empty> AND cond is none, not in <empty> AND cond is the rows of cond.
/// Both sides of the operator are tried, for props (where) and base fields (whereRedb).
/// Every object hangs under this instance's own parent, so parallel runs never see each other's rows.
///
public abstract class RedbQueryConstantInsideOrIntegrationTests : IAsyncLifetime
{
private readonly IRedbService _redb;
private readonly string _tag = Guid.NewGuid().ToString("N");
private readonly List _created = [];
private long _parent;
private long _first;
private long _second;
protected RedbQueryConstantInsideOrIntegrationTests(IRedbService redb) => _redb = redb;
public async Task InitializeAsync()
{
await _redb.SyncSchemeAsync();
_parent = await Save(new RedbObject(new QueryProbeProps { Tag = _tag, Rank = 0 }));
_first = await Save(new RedbObject(new QueryProbeProps { Tag = _tag, Rank = 1 })
{ ParentId = _parent, ValueString = "A-" + _tag });
_second = await Save(new RedbObject(new QueryProbeProps { Tag = _tag, Rank = 2 })
{ ParentId = _parent, ValueString = "B-" + _tag });
}
public async Task DisposeAsync()
{
// Children first, then the parent.
foreach (var id in Enumerable.Reverse(_created))
await _redb.DeleteAsync(id);
}
private async Task Save(RedbObject entity)
{
var id = await _redb.SaveAsync(entity);
_created.Add(id);
return id;
}
private async Task> Ranks(string? where, string whereRedb)
{
await using var context = new RouteContext();
context.AddService(typeof(IRedbService), _redb);
context.AddRoutes(r => r.From("direct://probe")
.RedbQuery(typeof(QueryProbeProps), where: where, whereRedb: whereRedb));
await context.Start();
var producer = context.GetEndpoint("direct://probe").CreateProducer();
await producer.Start();
var exchange = new Exchange(new Message(null));
exchange.In.Headers["parent"] = _parent;
exchange.In.Headers["second"] = _second;
exchange.In.Headers["none"] = new List();
await producer.Process(exchange);
exchange.Exception.Should().BeNull();
return exchange.In.Body.Should().BeOfType>>().Subject
.Select(o => o.Props.Rank).OrderBy(r => r).ToList();
}
[Theory]
[InlineData("Tag in header.none OR Rank >= 2", new[] { 2 })]
[InlineData("Rank >= 2 OR Tag in header.none", new[] { 2 })]
[InlineData("Tag not in header.none OR Rank >= 2", new[] { 1, 2 })]
[InlineData("Rank >= 2 OR Tag not in header.none", new[] { 1, 2 })]
[InlineData("Tag in header.none AND Rank >= 2", new int[0])]
[InlineData("Rank >= 2 AND Tag in header.none", new int[0])]
[InlineData("Tag not in header.none AND Rank >= 2", new[] { 2 })]
[InlineData("Rank >= 2 AND Tag not in header.none", new[] { 2 })]
public async Task Props_empty_list_beside_a_condition_returns_the_rows_linq_gives(string where, int[] expected)
{
var ranks = await Ranks(where, "ParentId == header.parent");
ranks.Should().Equal(expected, $"where: {where}");
}
[Theory]
[InlineData("ValueString in header.none OR Id == header.second", new[] { 2 })]
[InlineData("Id == header.second OR ValueString in header.none", new[] { 2 })]
[InlineData("ValueString not in header.none OR Id == header.second", new[] { 1, 2 })]
[InlineData("Id == header.second OR ValueString not in header.none", new[] { 1, 2 })]
[InlineData("ValueString in header.none AND Id == header.second", new int[0])]
[InlineData("Id == header.second AND ValueString in header.none", new int[0])]
[InlineData("ValueString not in header.none AND Id == header.second", new[] { 2 })]
[InlineData("Id == header.second AND ValueString not in header.none", new[] { 2 })]
public async Task Base_field_empty_list_beside_a_condition_returns_the_rows_linq_gives(string condition, int[] expected)
{
var whereRedb = $"ParentId == header.parent AND ({condition})";
var ranks = await Ranks(null, whereRedb);
ranks.Should().Equal(expected, $"whereRedb: {whereRedb}");
}
}
[Collection("Postgres")]
public sealed class PostgresRedbQueryConstantInsideOrTests(PostgresFixture fixture)
: RedbQueryConstantInsideOrIntegrationTests(fixture.Redb);
[Collection("MsSql")]
public sealed class MsSqlRedbQueryConstantInsideOrTests(MsSqlFixture fixture)
: RedbQueryConstantInsideOrIntegrationTests(fixture.Redb);