@@ -7,53 +7,27 @@ namespace TestingUtils
77{
88 class UnitTestDetector
99 {
10- private static bool ? _inUnitTestRunner ;
10+ public static bool IsCI ( ) => string . IsNullOrWhiteSpace ( Environment . GetEnvironmentVariable ( "CI" ) )
11+ && string . IsNullOrWhiteSpace ( Environment . GetEnvironmentVariable ( "TF_BUILD" ) ) ;
1112
12- public static bool InUnitTestRunner ( )
13+ public static bool PlatformToSkipPredicate ( SkipOnPlatform platform )
1314 {
14- if ( _inUnitTestRunner . HasValue ) return _inUnitTestRunner . Value ;
15-
16- var testAssemblies = new [ ] {
17- "CSUNIT" ,
18- "NUNIT" ,
19- "XUNIT" ,
20- "MBUNIT" ,
21- "NBEHAVE" ,
22- "VISUALSTUDIO.QUALITYTOOLS" ,
23- "VISUALSTUDIO.TESTPLATFORM" ,
24- "FIXIE" ,
25- "NCRUNCH" ,
26- } ;
27-
28- try
29- {
30- _inUnitTestRunner = SearchForAssembly ( testAssemblies ) ;
31- }
32- catch ( Exception e )
33- {
34- _inUnitTestRunner = false ;
35- }
36-
37- return _inUnitTestRunner . Value ;
38- }
39-
40- public static bool IsCI ( ) => string . IsNullOrWhiteSpace ( Environment . GetEnvironmentVariable ( "CI" ) ) && string . IsNullOrWhiteSpace ( Environment . GetEnvironmentVariable ( "TF_BUILD" ) ) ;
41-
42- public static bool PlatformToSkipPredicate ( SkipOnPlatform platform ) =>
43- RuntimeInformation . IsOSPlatform (
44- platform switch {
45- SkipOnPlatform . Linux => OSPlatform . Linux ,
46- SkipOnPlatform . Mac => OSPlatform . OSX ,
47- SkipOnPlatform . Windows => OSPlatform . Windows ,
48- _ => OSPlatform . Create ( "Unknown" )
49- }
50- ) ;
51-
52- private static bool SearchForAssembly ( IEnumerable < string > assemblyList )
53- {
54- return AppDomain . CurrentDomain . GetAssemblies ( )
55- . Select ( x => x . FullName . ToUpperInvariant ( ) )
56- . Any ( x => assemblyList . Any ( name => x . IndexOf ( name , StringComparison . InvariantCultureIgnoreCase ) != - 1 ) ) ;
15+ if ( platform == SkipOnPlatform . All ) return true ;
16+ if ( platform == SkipOnPlatform . None ) return false ;
17+ return Enum . GetValues ( typeof ( SkipOnPlatform ) )
18+ . OfType < SkipOnPlatform > ( )
19+ . Where ( z => z != SkipOnPlatform . All && z != SkipOnPlatform . None )
20+ . Where ( z => ( platform & z ) == z )
21+ . Any (
22+ z => RuntimeInformation . IsOSPlatform (
23+ platform switch {
24+ SkipOnPlatform . Linux => OSPlatform . Linux ,
25+ SkipOnPlatform . Mac => OSPlatform . OSX ,
26+ SkipOnPlatform . Windows => OSPlatform . Windows ,
27+ _ => OSPlatform . Create ( "Unknown" )
28+ }
29+ )
30+ ) ;
5731 }
5832 }
59- }
33+ }
0 commit comments