22// SPDX-License-Identifier: Apache-2.0
33
44using System . Collections . Specialized ;
5+ using System . Globalization ;
56using System . Reflection ;
67using System . Runtime . InteropServices ;
78using System . Runtime . Versioning ;
89using Xunit . Abstractions ;
910
1011namespace IntegrationTests . Helpers ;
1112
12- public class EnvironmentHelper
13+ internal sealed class EnvironmentHelper
1314{
14- private static readonly string RuntimeFrameworkDescription = RuntimeInformation . FrameworkDescription . ToLower ( ) ;
15+ #pragma warning disable CA1308 // Normalize strings to uppercase
16+ private static readonly string RuntimeFrameworkDescription = RuntimeInformation . FrameworkDescription . ToLowerInvariant ( ) ;
17+ #pragma warning restore CA1308 // Normalize strings to uppercase
1518
1619 private readonly ITestOutputHelper _output ;
1720 private readonly int _major ;
@@ -41,11 +44,15 @@ public EnvironmentHelper(
4144
4245 var parts = _targetFramework . FrameworkName . Split ( ',' ) ;
4346 _runtime = parts [ 0 ] ;
44- _isCoreClr = _runtime . Equals ( EnvironmentTools . CoreFramework ) ;
47+ _isCoreClr = _runtime . Equals ( EnvironmentTools . CoreFramework , StringComparison . Ordinal ) ;
4548
49+ #if NET
50+ var versionParts = parts [ 1 ] . Replace ( "Version=v" , string . Empty , StringComparison . Ordinal ) . Split ( '.' ) ;
51+ #else
4652 var versionParts = parts [ 1 ] . Replace ( "Version=v" , string . Empty ) . Split ( '.' ) ;
47- _major = int . Parse ( versionParts [ 0 ] ) ;
48- _minor = int . Parse ( versionParts [ 1 ] ) ;
53+ #endif
54+ _major = int . Parse ( versionParts [ 0 ] , CultureInfo . InvariantCulture ) ;
55+ _minor = int . Parse ( versionParts [ 1 ] , CultureInfo . InvariantCulture ) ;
4956
5057 if ( versionParts . Length == 3 )
5158 {
@@ -77,7 +84,13 @@ public EnvironmentHelper(
7784
7885 public static bool IsCoreClr ( )
7986 {
80- return RuntimeFrameworkDescription . Contains ( "core" ) || Environment . Version . Major >= 5 ;
87+ return
88+ #if NET
89+ RuntimeFrameworkDescription . Contains ( "core" , StringComparison . Ordinal )
90+ #else
91+ RuntimeFrameworkDescription . Contains ( "core" )
92+ #endif
93+ || Environment . Version . Major >= 5 ;
8194 }
8295
8396 public static string GetNukeBuildOutput ( )
@@ -92,7 +105,7 @@ public static string GetNukeBuildOutput()
92105 return nukeOutputPath ;
93106 }
94107
95- throw new Exception ( $ "Unable to find Nuke output at: { nukeOutputPath } . Ensure Nuke has run first.") ;
108+ throw new InvalidOperationException ( $ "Unable to find Nuke output at: { nukeOutputPath } . Ensure Nuke has run first.") ;
96109 }
97110
98111 public static bool IsRunningOnCI ( )
@@ -138,14 +151,20 @@ public string GetProfilerPath()
138151 return _profilerFileLocation ;
139152 }
140153
141- throw new Exception ( $ "Unable to find profiler at: { profilerPath } ") ;
154+ throw new InvalidOperationException ( $ "Unable to find profiler at: { profilerPath } ") ;
142155 }
143156
144157 public string GetTestApplicationPath ( string packageVersion = "" , string framework = "" , TestAppStartupMode startupMode = TestAppStartupMode . Auto )
145158 {
146159 var extension = startupMode switch
147160 {
148- TestAppStartupMode . Auto => IsCoreClr ( ) || _testApplicationDirectory . Contains ( "aspnet" ) ? ".dll" : GetExecutableExtension ( ) ,
161+ TestAppStartupMode . Auto => IsCoreClr ( ) ||
162+ #if NET
163+ _testApplicationDirectory . Contains ( "aspnet" , StringComparison . Ordinal )
164+ #else
165+ _testApplicationDirectory . Contains ( "aspnet" )
166+ #endif
167+ ? ".dll" : GetExecutableExtension ( ) ,
149168 TestAppStartupMode . DotnetCLI => ".dll" ,
150169 TestAppStartupMode . Exe => GetExecutableExtension ( ) ,
151170 _ => throw new InvalidOperationException ( $ "Unknown startup mode '{ startupMode } '")
@@ -165,7 +184,11 @@ public string GetTestApplicationExecutionSource()
165184 {
166185 string executor ;
167186
187+ #if NET
188+ if ( _testApplicationDirectory . Contains ( "aspnet" , StringComparison . Ordinal ) )
189+ #else
168190 if ( _testApplicationDirectory . Contains ( "aspnet" ) )
191+ #endif
169192 {
170193 executor = $ "C:\\ Program Files{ ( Environment . Is64BitProcess ? string . Empty : " (x86)" ) } \\ IIS Express\\ iisexpress.exe";
171194 }
@@ -180,7 +203,7 @@ public string GetTestApplicationExecutionSource()
180203
181204 if ( ! File . Exists ( executor ) )
182205 {
183- throw new Exception ( $ "Unable to find executing assembly at { executor } ") ;
206+ throw new InvalidOperationException ( $ "Unable to find executing assembly at { executor } ") ;
184207 }
185208 }
186209
@@ -203,7 +226,11 @@ public string GetTestApplicationApplicationOutputDirectory(string packageVersion
203226 var targetFramework = string . IsNullOrEmpty ( framework ) ? GetTargetFramework ( ) : framework ;
204227 var baseBinDirectory = GetTestApplicationBaseBinDirectory ( ) ;
205228
229+ #if NET
230+ if ( _testApplicationDirectory . Contains ( "aspnet" , StringComparison . Ordinal ) )
231+ #else
206232 if ( _testApplicationDirectory . Contains ( "aspnet" ) )
233+ #endif
207234 {
208235 return Path . Combine (
209236 baseBinDirectory ,
0 commit comments