using Eis.Infrastructure.Administration; namespace Eis.Infrastructure.Tests.Administration; public sealed class AdminMigrationOptionsTests { [Fact] public void DisabledByDefault() { WithEnvironment(null, null, () => { var options = AdminMigrationOptions.FromEnvironment( configuredNativeReadsEnabled: false, authenticationNativeEnabled: false, sharesLegacySessions: false); Assert.False(options.NativeReadsEnabled); }); } [Fact] public void RequiresNativeAuthentication() { WithEnvironment("true", "true", () => { var exception = Assert.Throws(() => AdminMigrationOptions.FromEnvironment( configuredNativeReadsEnabled: false, authenticationNativeEnabled: false, sharesLegacySessions: false)); Assert.Contains("AUTH_NATIVE_ENABLED=true", exception.Message); }); } [Fact] public void RequiresSharedSessionsOutsideIsolatedTests() { WithEnvironment("true", null, () => { var exception = Assert.Throws(() => AdminMigrationOptions.FromEnvironment( configuredNativeReadsEnabled: false, authenticationNativeEnabled: true, sharesLegacySessions: false)); Assert.Contains("Redis", exception.Message); }); } [Fact] public void AllowsSharedRedisSessions() { WithEnvironment("true", null, () => { var options = AdminMigrationOptions.FromEnvironment( configuredNativeReadsEnabled: false, authenticationNativeEnabled: true, sharesLegacySessions: true); Assert.True(options.NativeReadsEnabled); }); } private static void WithEnvironment( string? nativeReadsEnabled, string? allowMemory, Action test) { var previousNativeReadsEnabled = Environment.GetEnvironmentVariable("ADMIN_NATIVE_READS_ENABLED"); var previousAllowMemory = Environment.GetEnvironmentVariable("ADMIN_NATIVE_ALLOW_MEMORY"); try { Environment.SetEnvironmentVariable("ADMIN_NATIVE_READS_ENABLED", nativeReadsEnabled); Environment.SetEnvironmentVariable("ADMIN_NATIVE_ALLOW_MEMORY", allowMemory); test(); } finally { Environment.SetEnvironmentVariable("ADMIN_NATIVE_READS_ENABLED", previousNativeReadsEnabled); Environment.SetEnvironmentVariable("ADMIN_NATIVE_ALLOW_MEMORY", previousAllowMemory); } } }