22using System . IO ;
33using SeqCli . Config ;
44using Xunit ;
5+ using Xunit . Sdk ;
56
67namespace SeqCli . Tests . Config ;
78
@@ -16,15 +17,31 @@ public void DefaultConfigFilename()
1617 }
1718
1819 [ Fact ]
20+ [ EnvironmentOverridenConfigFilenameBeforeAfter ( SeqCliConfigFile = "MyCustomSeqCli.json" ) ]
1921 public void EnvironmentOverridenConfigFilename ( )
2022 {
21- var tempConfigFile = Path . GetTempFileName ( ) ;
22- Environment . SetEnvironmentVariable ( "SEQCLI_CONFIG_FILE" , tempConfigFile ) ;
2323 var configFile = RuntimeConfigurationLoader . SeqCliConfigFilename ( ) ;
24- // Clean up immediately to avoid affecting environment for other tests
25- // TODO: Or better move to public void Dispose() ?
26- Environment . SetEnvironmentVariable ( "SEQCLI_CONFIG_FILE" , null ) ;
24+ var customConfigFile = Path . Combine ( Path . GetTempPath ( ) , "MyCustomSeqCli.json" ) ;
25+ Assert . Equal ( customConfigFile , configFile ) ;
26+ }
27+ }
28+
29+ [ AttributeUsage ( AttributeTargets . Method , Inherited = false , AllowMultiple = false ) ]
30+ public class EnvironmentOverridenConfigFilenameBeforeAfter : BeforeAfterTestAttribute
31+ {
32+ private string originalValue ;
33+ public string SeqCliConfigFile { get ; set ; }
34+
35+ public override void Before ( System . Reflection . MethodInfo methodUnderTest )
36+ {
37+ originalValue = Environment . GetEnvironmentVariable ( "SEQCLI_CONFIG_FILE" ) ;
38+
39+ var configFile = Path . Combine ( Path . GetTempPath ( ) , SeqCliConfigFile ) ;
40+ Environment . SetEnvironmentVariable ( "SEQCLI_CONFIG_FILE" , configFile ) ;
41+ }
2742
28- Assert . Equal ( tempConfigFile , configFile ) ;
43+ public override void After ( System . Reflection . MethodInfo methodUnderTest )
44+ {
45+ Environment . SetEnvironmentVariable ( "SEQCLI_CONFIG_FILE" , originalValue ) ;
2946 }
3047}
0 commit comments