Path: redb/redb.Tests.Integration/Tests/Unit/RedbServiceConfigurationCopyTests.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/RedbServiceConfigurationCopyTests.cs
----
using System.Reflection;
using redb.Core.Models.Configuration;
namespace redb.Tests.Integration.Tests.Unit;
///
/// Copying a configuration (review CFG-1). Clone listed its settings by hand and had fallen behind: five of them
/// (AutoApplyDatabaseUpgrades, StringCollation, EnablePvtPrefilter, PropsSaveStrategy,
/// DefaultCheckPermissionsOnQuery) came back at their defaults, so a configuration "fixed" by the validator could
/// switch automatic schema upgrades back on. Every writable setting is set here to a value that is not its default
/// and must survive the copy - a setting added later without being copied fails this test. No database required.
///
public class RedbServiceConfigurationCopyTests
{
private static readonly PropertyInfo[] Settings = typeof(RedbServiceConfiguration)
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead && p.CanWrite)
.ToArray();
/// The identity of a connection, as opposed to the behaviour settings a temporary scope may change.
private static readonly string[] Identity =
[nameof(RedbServiceConfiguration.ConnectionString), nameof(RedbServiceConfiguration.CacheDomain)];
private static RedbServiceConfiguration WithEverySettingChanged()
{
var config = new RedbServiceConfiguration();
foreach (var p in Settings)
p.SetValue(config, NotTheDefault(p, p.GetValue(config)));
return config;
}
private static object? NotTheDefault(PropertyInfo p, object? current) => p.PropertyType switch
{
var t when t == typeof(bool) => !(bool)current!,
var t when t == typeof(int) => 7, // valid for every ranged int setting, the default of none
var t when t == typeof(long) => 7L,
var t when t == typeof(TimeSpan) => TimeSpan.FromMinutes(3),
var t when t == typeof(TimeSpan?) => TimeSpan.FromMinutes(3),
var t when t == typeof(string) => "und-x-icu", // a valid collation name, and a valid anything else
var t when t.IsEnum => Enum.GetValues(t).Cast