1
+ using System ;
2
+ using System . Globalization ;
3
+ using System . Linq ;
4
+ using Xunit ;
5
+
6
+ namespace LyricsScraperNET . TestShared . Attributes
7
+ {
8
+ [ AttributeUsage ( AttributeTargets . Method , AllowMultiple = false ) ]
9
+ public class RegionalTestTheoryAttribute : TheoryAttribute
10
+ {
11
+ public RegionalTestTheoryAttribute ( string [ ] includeRegions = null , string [ ] excludeRegions = null )
12
+ {
13
+ if ( ! ShouldRunTest ( includeRegions , excludeRegions ) )
14
+ {
15
+ Skip = GenerateSkipMessage ( includeRegions , excludeRegions ) ;
16
+ }
17
+ }
18
+
19
+ private static bool ShouldRunTest ( string [ ] includeRegions , string [ ] excludeRegions )
20
+ {
21
+ var currentRegion = RegionInfo . CurrentRegion . Name ;
22
+
23
+ // If regions are specified to be included, run only if the current region is in the list.
24
+ if ( includeRegions != null && includeRegions . Length > 0 )
25
+ {
26
+ if ( ! includeRegions . Any ( code => string . Equals ( currentRegion , code , StringComparison . OrdinalIgnoreCase ) ) )
27
+ {
28
+ return false ;
29
+ }
30
+ }
31
+
32
+ // If regions are specified to be excluded, do not run if the current region is in the list.
33
+ if ( excludeRegions != null && excludeRegions . Length > 0 )
34
+ {
35
+ if ( excludeRegions . Any ( code => string . Equals ( currentRegion , code , StringComparison . OrdinalIgnoreCase ) ) )
36
+ {
37
+ return false ;
38
+ }
39
+ }
40
+
41
+ return true ;
42
+ }
43
+
44
+ private static string GenerateSkipMessage ( string [ ] includeRegions , string [ ] excludeRegions )
45
+ {
46
+ var includeMessage = includeRegions != null && includeRegions . Length > 0
47
+ ? $ "Include: { string . Join ( ", " , includeRegions ) } ."
48
+ : string . Empty ;
49
+
50
+ var excludeMessage = excludeRegions != null && excludeRegions . Length > 0
51
+ ? $ "Exclude: { string . Join ( ", " , excludeRegions ) } ."
52
+ : string . Empty ;
53
+
54
+ return $ "Test skipped. { includeMessage } { excludeMessage } ". Trim ( ) ;
55
+ }
56
+ }
57
+ }
0 commit comments