11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
34using System . Reflection ;
45using Xunit ;
@@ -8,6 +9,8 @@ namespace Tests.Framework
89{
910 public class IntegrationTestDiscoverer : NestTestDiscoverer
1011 {
12+ private bool RunningOnTeamCity { get ; } = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "TEAMCITY_VERSION" ) ) ;
13+
1114 public IntegrationTestDiscoverer ( IMessageSink diagnosticMessageSink )
1215 : base ( diagnosticMessageSink , TestClient . Configuration . RunIntegrationTests ) { }
1316
@@ -17,29 +20,33 @@ protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptio
1720 var method = classOfMethod . GetMethod ( testMethod . Method . Name , BindingFlags . FlattenHierarchy | BindingFlags . NonPublic | BindingFlags . Public )
1821 ?? testMethod . Method . ToRuntimeMethod ( ) ;
1922
20- return TypeSkipVersionAttributeSatisfies ( classOfMethod ) ||
21- MethodSkipVersionAttributeSatisfies ( method ) ;
23+ return TypeSkipVersionAttributeSatisfies ( classOfMethod )
24+ || MethodSkipVersionAttributeSatisfies ( method )
25+ || SkipWhenRunOnTeamCity ( classOfMethod , method ) ;
2226 }
2327
24-
25- private static bool TypeSkipVersionAttributeSatisfies ( Type classOfMethod )
28+ private bool SkipWhenRunOnTeamCity ( Type classOfMethod , MethodInfo info )
2629 {
27- var attributes = classOfMethod . GetAttributes < SkipVersionAttribute > ( ) ;
28- if ( ! attributes . Any ( ) ) return false ;
30+ if ( ! this . RunningOnTeamCity ) return false ;
2931
30- return attributes
31- . SelectMany ( a => a . Ranges )
32- . Any ( range => TestClient . VersionUnderTestSatisfiedBy ( range . ToString ( ) ) ) ;
32+ var attributes = classOfMethod . GetAttributes < SkipOnTeamCityAttribute > ( ) . Concat ( info . GetAttributes < SkipOnTeamCityAttribute > ( ) ) ;
33+ return attributes . Any ( ) ;
3334 }
3435
35- private static bool MethodSkipVersionAttributeSatisfies ( MethodInfo methodInfo )
36+ private static bool TypeSkipVersionAttributeSatisfies ( Type classOfMethod ) =>
37+ VersionUnderTestMatchesAttribute ( classOfMethod . GetAttributes < SkipVersionAttribute > ( ) ) ;
38+
39+ private static bool MethodSkipVersionAttributeSatisfies ( MethodInfo methodInfo ) =>
40+ VersionUnderTestMatchesAttribute ( methodInfo . GetAttributes < SkipVersionAttribute > ( ) ) ;
41+
42+ private static bool VersionUnderTestMatchesAttribute ( IEnumerable < SkipVersionAttribute > attributes )
3643 {
37- var attributes = methodInfo . GetAttributes < SkipVersionAttribute > ( ) ;
3844 if ( ! attributes . Any ( ) ) return false ;
3945
4046 return attributes
4147 . SelectMany ( a => a . Ranges )
4248 . Any ( range => TestClient . VersionUnderTestSatisfiedBy ( range . ToString ( ) ) ) ;
4349 }
50+
4451 }
4552}
0 commit comments