1
+ using System ;
2
+ using Exceptionless . Plugins ;
3
+ using Exceptionless . Plugins . Default ;
4
+ using Exceptionless . Models ;
5
+ using Xunit ;
6
+ using Xunit . Abstractions ;
7
+
8
+ namespace Exceptionless . Tests . Plugins {
9
+ public class EventExclusionPluginTests : PluginTestBase {
10
+ public EventExclusionPluginTests ( ITestOutputHelper output ) : base ( output ) { }
11
+
12
+ [ Fact ]
13
+ public void EventExclusions ( ) {
14
+ var client = CreateClient ( ) ;
15
+ var plugin = new EventExclusionPlugin ( ) ;
16
+
17
+ // ignore any event that has a value of 2
18
+ client . Configuration . AddEventExclusion ( e => e . Value . GetValueOrDefault ( ) != 2 ) ;
19
+
20
+ var ev = new Event { Value = 1 } ;
21
+ var context = new EventPluginContext ( client , ev ) ;
22
+ plugin . Run ( context ) ;
23
+ Assert . False ( context . Cancel ) ;
24
+
25
+ ev . Value = 2 ;
26
+ context = new EventPluginContext ( client , ev ) ;
27
+ plugin . Run ( context ) ;
28
+ Assert . True ( context . Cancel ) ;
29
+ }
30
+
31
+ [ Theory ]
32
+ [ InlineData ( null , null , null , null , false ) ]
33
+ [ InlineData ( "Test" , null , null , null , false ) ]
34
+ [ InlineData ( "Test" , "Trace" , null , null , false ) ]
35
+ [ InlineData ( "Test" , "Off" , null , null , true ) ]
36
+ [ InlineData ( "Test" , "Abc" , null , null , false ) ]
37
+ [ InlineData ( null , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix , "Off" , true ) ]
38
+ [ InlineData ( null , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "*" , "Off" , true ) ]
39
+ [ InlineData ( "" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix , "Off" , true ) ] // Becomes Global Log Level
40
+ [ InlineData ( "" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "*" , "Off" , true ) ]
41
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "Debug" , true ) ]
42
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "false" , true ) ]
43
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "no" , true ) ]
44
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "0" , true ) ]
45
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "true" , false ) ]
46
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "yes" , false ) ]
47
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "1" , false ) ]
48
+ [ InlineData ( "Test" , "Info" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "Debug" , false ) ]
49
+ [ InlineData ( "Test" , "Trace" , SettingsDictionary . KnownKeys . LogLevelPrefix + "*" , "Debug" , true ) ]
50
+ [ InlineData ( "Test" , "Warn" , SettingsDictionary . KnownKeys . LogLevelPrefix + "*" , "Debug" , false ) ]
51
+ [ InlineData ( "Test" , "Warn" , SettingsDictionary . KnownKeys . LogLevelPrefix + "*" , "Off" , true ) ]
52
+ public void LogLevels ( string source , string level , string settingKey , string settingValue , bool cancelled ) {
53
+ var client = CreateClient ( ) ;
54
+ if ( settingKey != null )
55
+ client . Configuration . Settings . Add ( settingKey , settingValue ) ;
56
+
57
+ var ev = new Event { Type = Event . KnownTypes . Log , Source = source } ;
58
+ if ( ! String . IsNullOrEmpty ( level ) )
59
+ ev . SetProperty ( Event . KnownDataKeys . Level , level ) ;
60
+
61
+ var context = new EventPluginContext ( client , ev ) ;
62
+ var plugin = new EventExclusionPlugin ( ) ;
63
+ plugin . Run ( context ) ;
64
+ Assert . Equal ( cancelled , context . Cancel ) ;
65
+ }
66
+
67
+ [ Theory ]
68
+ [ InlineData ( null , null , null , null , false ) ]
69
+ [ InlineData ( "usage" , null , null , null , false ) ]
70
+ [ InlineData ( "usage" , "test" , null , null , false ) ]
71
+ [ InlineData ( "usage" , "test" , "@@usage:Test" , "true" , false ) ]
72
+ [ InlineData ( "usage" , "test" , "@@usage:Test" , "false" , true ) ]
73
+ [ InlineData ( "usage" , "EX-FEAT: 1234567890" , "@@usage:EX-FEAT: 1234567890" , "false" , true ) ]
74
+ [ InlineData ( "usage" , "test" , "@@usage:*" , "false" , true ) ]
75
+ [ InlineData ( "404" , null , "@@404:*" , "false" , true ) ]
76
+ [ InlineData ( "404" , null , "@@404:" , "false" , true ) ]
77
+ [ InlineData ( "404" , "" , "@@404:" , "false" , true ) ]
78
+ [ InlineData ( "404" , "/unknown" , "@@404:*" , "false" , true ) ]
79
+ [ InlineData ( "404" , "/unknown" , "@@404:/unknown" , "false" , true ) ]
80
+ [ InlineData ( "404" , "/unknown" , "@@404:/unknown" , "true" , false ) ]
81
+ [ InlineData ( "404" , "/example.php" , "@@404:*.php" , "false" , true ) ]
82
+ public void SourceType ( string type , string source , string settingKey , string settingValue , bool cancelled ) {
83
+ var client = CreateClient ( ) ;
84
+ if ( settingKey != null )
85
+ client . Configuration . Settings . Add ( settingKey , settingValue ) ;
86
+
87
+ var ev = new Event { Type = type , Source = source } ;
88
+ var context = new EventPluginContext ( client , ev ) ;
89
+ var plugin = new EventExclusionPlugin ( ) ;
90
+ plugin . Run ( context ) ;
91
+ Assert . Equal ( cancelled , context . Cancel ) ;
92
+ Assert . Equal ( source , ev . Source ) ;
93
+ }
94
+
95
+ [ Theory ]
96
+ [ InlineData ( null , null , null , null , false ) ]
97
+ [ InlineData ( "Test" , null , null , null , false ) ]
98
+ [ InlineData ( "Test" , "Trace" , null , null , true ) ]
99
+ [ InlineData ( "Test" , "Warn" , null , null , false ) ]
100
+ [ InlineData ( "Test" , "Error" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "Debug" , false ) ]
101
+ [ InlineData ( "Test" , "Debug" , SettingsDictionary . KnownKeys . LogLevelPrefix + "Test" , "Debug" , false ) ]
102
+ public void LogLevelsWithInfoDefault ( string source , string level , string settingKey , string settingValue , bool cancelled ) {
103
+ var client = CreateClient ( ) ;
104
+ client . Configuration . Settings . Add ( SettingsDictionary . KnownKeys . LogLevelPrefix + "*" , "Info" ) ;
105
+ if ( settingKey != null )
106
+ client . Configuration . Settings . Add ( settingKey , settingValue ) ;
107
+
108
+ var ev = new Event { Type = Event . KnownTypes . Log , Source = source } ;
109
+ if ( ! String . IsNullOrEmpty ( level ) )
110
+ ev . SetProperty ( Event . KnownDataKeys . Level , level ) ;
111
+
112
+ var context = new EventPluginContext ( client , ev ) ;
113
+ var plugin = new EventExclusionPlugin ( ) ;
114
+ plugin . Run ( context ) ;
115
+ Assert . Equal ( cancelled , context . Cancel ) ;
116
+ }
117
+
118
+ [ Theory ]
119
+ [ InlineData ( null , false ) ]
120
+ [ InlineData ( "@@error:TestException" , false ) ]
121
+ [ InlineData ( "@@error:Exception" , false ) ]
122
+ [ InlineData ( "@@error:System.Exception" , true ) ]
123
+ [ InlineData ( "@@error:*Exception" , true ) ]
124
+ [ InlineData ( "@@error:*" , true ) ]
125
+ public void ExceptionType ( string settingKey , bool cancelled ) {
126
+ var client = CreateClient ( ) ;
127
+ if ( settingKey != null )
128
+ client . Configuration . Settings . Add ( settingKey , Boolean . FalseString ) ;
129
+
130
+ var plugin = new EventExclusionPlugin ( ) ;
131
+ var context = new EventPluginContext ( client , new Event ( ) ) ;
132
+ context . ContextData . SetException ( GetException ( ) ) ;
133
+ plugin . Run ( context ) ;
134
+ Assert . Equal ( cancelled , context . Cancel ) ;
135
+
136
+ context . ContextData . SetException ( GetNestedSimpleException ( ) ) ;
137
+ plugin . Run ( context ) ;
138
+ Assert . Equal ( cancelled , context . Cancel ) ;
139
+ }
140
+ }
141
+ }
0 commit comments