Path: redb/redb.Tests.Integration/Tests/Base/DictionaryOrderTestsBase.cs Snapshot: redb, 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 Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Base/DictionaryOrderTestsBase.cs ---- using redb.Core; using redb.Core.Models.Contracts; using redb.Core.Models.Entities; using redb.Tests.Integration.Models; namespace redb.Tests.Integration.Tests.Base; /// /// A dictionary reads back with its entries in the order of their keys, at the top level and inside an element of an /// array of classes, by a load and by a query, the same on every provider. The entries came in the order of the rows /// of the read in Pro (which moved between reads and between its planner modes) and of the JSON the free modules built: /// by key length on PostgreSQL, by the collation of the key text on SQL Server (Zulu after zeta). SQLite Free already /// listed them by key. /// public abstract class DictionaryOrderTestsBase { protected readonly IRedbService Redb; protected DictionaryOrderTestsBase(IRedbService redb) => Redb = redb; private static readonly string[] TopKeys = ["zeta", "alpha", "mu", "beta", "omega", "kappa", "Zulu"]; private static readonly int[] NumberKeys = [10, 2, -3, 100, 0, 21]; private static readonly string[] LabelKeys = ["z", "a", "m", "b", "y", "c"]; private static DictionaryOrderProps Sample(string tag, int n) => new() { Tag = tag, Top = TopKeys.Select((k, i) => (k, i)).ToDictionary(e => e.k, e => e.i + n), Numbered = NumberKeys.ToDictionary(k => k, k => $"{k}-{n}"), Rows = [ new() { Name = "r0", Labels = LabelKeys.ToDictionary(k => k, k => k + n) }, new() { Name = "r1", Labels = LabelKeys.Reverse().ToDictionary(k => k, k => k + n) }, ] }; private static void AssertKeyOrder(DictionaryOrderProps props, int n) { props.Top!.Keys.Should().Equal(TopKeys.Order(StringComparer.Ordinal)); props.Top.Should().BeEquivalentTo(Sample(props.Tag, n).Top); props.Numbered!.Keys.Should().Equal(NumberKeys.Order()); props.Rows![0].Labels!.Keys.Should().Equal(LabelKeys.Order(StringComparer.Ordinal)); props.Rows![1].Labels!.Keys.Should().Equal(LabelKeys.Order(StringComparer.Ordinal)); } [Fact] public async Task Dictionary_ReadsBackInTheOrderOfItsKeys() { await Redb.SyncSchemeAsync(); var tag = "dor-" + Guid.NewGuid().ToString("N")[..8]; var objects = Enumerable.Range(0, 5) .Select(n => (IRedbObject)new RedbObject { name = $"{tag}-{n}", Props = Sample(tag, n) }) .ToList(); await Redb.SaveAsync(objects); for (var n = 0; n < objects.Count; n++) AssertKeyOrder((await Redb.LoadAsync(objects[n].Id))!.Props, n); var queried = await Redb.Query().Where(p => p.Tag == tag).ToListAsync(); queried.Should().HaveCount(objects.Count); foreach (var o in queried) AssertKeyOrder(o.Props, int.Parse(o.name[(tag.Length + 1)..])); } }