Path: redb/redb.Tests.Integration/Tests/Unit/NestedDictionaryIndexerRefusalTests.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/Unit/NestedDictionaryIndexerRefusalTests.cs
----
using System.Linq.Expressions;
using redb.Core.Pro.Query;
using redb.Core.Query;
using redb.Core.Query.QueryExpressions;
namespace redb.Tests.Integration.Tests.Unit;
///
/// A dictionary entry read through another dictionary entry (D["a"]["b"]) is not a chain of fields of the
/// queried object: the filter refuses it with the field path message. It used to reach the query with the outer
/// dictionary cut to the literal "Dict" in its path. One dictionary entry, with or without a field of its value, is
/// read. No database is needed: the parser decides.
///
public class NestedDictionaryIndexerRefusalTests
{
public class Entry
{
public string Name { get; set; } = "";
}
public class NestedDictionaryProps
{
public Dictionary> ByGroup { get; set; } = new();
public Dictionary> Counts { get; set; } = new();
public Dictionary ByKey { get; set; } = new();
public Dictionary Scores { get; set; } = new();
}
private readonly ProFilterExpressionParser _parser = new();
[Fact]
public void FieldOfAnEntryOfAnEntry_IsRefused()
{
var name = "x";
var act = () => _parser.ParseFilter(p => p.ByGroup["a"]["b"].Name == name);
act.Should().Throw()
.WithMessage(FieldPathRefusal.Message("p.ByGroup.get_Item(\"a\")"));
}
[Fact]
public void SimpleValueOfAnEntryOfAnEntry_IsRefused()
{
var act = () => _parser.ParseFilter(p => p.Counts["a"]["b"] == 5);
act.Should().Throw()
.WithMessage(FieldPathRefusal.Message("p.Counts.get_Item(\"a\")"));
}
[Fact]
public void FieldOfOneEntry_IsRead()
{
var result = _parser.ParseFilter(p => p.ByKey["a"].Name == "x");
var comparison = Assert.IsType(result);
comparison.Property.Name.Should().Be("ByKey[a].Name");
}
[Fact]
public void NullableValueOfOneEntry_IsRead()
{
var result = _parser.ParseFilter(p => p.Scores["a"].Value == 1);
var comparison = Assert.IsType(result);
comparison.Property.Name.Should().Be("Scores[a]");
}
}