1- // Copyright (C) 2010 Xtensive LLC.
2- // All rights reserved .
3- // For conditions of distribution and use, see license .
1+ // Copyright (C) 2010-2025 Xtensive LLC.
2+ // This code is distributed under MIT license terms .
3+ // See the License.txt file in the project root for more information .
44// Created by: Denis Krjuchkov
55// Created: 2010.02.11
66
@@ -17,6 +17,9 @@ public sealed class TestConfiguration
1717 private const string StorageFileKey = "DO_STORAGE_FILE" ;
1818 private const string ConfigurationFileKey = "DO_CONFIG_FILE" ;
1919
20+ private const string InfinityAliasesKey = "DO_PG_INFINITY_ALIASES" ;
21+ private const string LegacyTimestapmKey = "DO_PG_LEGACY_TIMESTAMP" ;
22+
2023 private const string DefaultStorage = "default" ;
2124
2225 private static readonly object InstanceLock = new object ( ) ;
@@ -53,6 +56,30 @@ public ConnectionInfo GetConnectionInfo(string name)
5356 return new ConnectionInfo ( items [ 0 ] , items [ 1 ] ) ;
5457 }
5558
59+ public void InitAppContextSwitches ( )
60+ {
61+ if ( configuration . TryGetValue ( Storage + "cs" , out var info ) ) {
62+ var items = info . Split ( new [ ] { '[' , ']' } , StringSplitOptions . RemoveEmptyEntries ) . Select ( i => i . Trim ( ) ) . ToArray ( ) ;
63+ if ( items . Length != 2 )
64+ throw new InvalidOperationException ( string . Format ( "Invalid connection string format: {0}" , info ) ) ;
65+ var provider = items [ 0 ] ;
66+ if ( provider . Equals ( WellKnown . Provider . PostgreSql , StringComparison . OrdinalIgnoreCase ) )
67+ InitPostgreSqlSwitches ( ) ;
68+ }
69+ }
70+
71+ private void InitPostgreSqlSwitches ( )
72+ {
73+ var infinityAliasesValue = GetEnvironmentVariable ( InfinityAliasesKey ) ;
74+ if ( bool . TryParse ( infinityAliasesValue , out var bbb ) ) {
75+ AppContext . SetSwitch ( "Npgsql.DisableDateTimeInfinityConversions" , ! bbb ) ;
76+ }
77+ var legacyTimestampsValue = GetEnvironmentVariable ( LegacyTimestapmKey ) ;
78+ if ( bool . TryParse ( legacyTimestampsValue , out var ccc ) ) {
79+ AppContext . SetSwitch ( "Npgsql.EnableLegacyTimestampBehavior" , ccc ) ;
80+ }
81+ }
82+
5683 private string GetEnvironmentVariable ( string key )
5784 {
5885 return new [ ] { EnvironmentVariableTarget . Process , EnvironmentVariableTarget . User , EnvironmentVariableTarget . Machine }
0 commit comments