1
1
using System ;
2
+ using System . Collections ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Threading . Tasks ;
@@ -89,7 +90,90 @@ public void ErrorPlugin_DiscardDuplicates() {
89
90
Assert . Null ( error ) ;
90
91
}
91
92
}
92
-
93
+
94
+ public static IEnumerable < object [ ] > DifferentExceptionDataDictionaryTypes {
95
+ get {
96
+ return new [ ] {
97
+ new object [ ] { null , false , 0 } ,
98
+ new object [ ] { new Dictionary < object , object > { { ( object ) 1 , ( object ) 1 } } , true , 1 } ,
99
+ new object [ ] { new Dictionary < PriorityAttribute , PriorityAttribute > ( ) { { new PriorityAttribute ( 1 ) , new PriorityAttribute ( 1 ) } } , false , 1 } ,
100
+ new object [ ] { new Dictionary < int , int > { { 1 , 1 } } , false , 1 } ,
101
+ new object [ ] { new Dictionary < bool , bool > { { false , false } } , false , 1 } ,
102
+ new object [ ] { new Dictionary < Guid , Guid > { { Guid . Empty , Guid . Empty } } , false , 1 } ,
103
+ new object [ ] { new Dictionary < IData , IData > { { new SimpleError ( ) , new SimpleError ( ) } } , false , 1 } ,
104
+ new object [ ] { new Dictionary < TestEnum , TestEnum > { { TestEnum . None , TestEnum . None } } , false , 1 } ,
105
+ new object [ ] { new Dictionary < TestStruct , TestStruct > { { new TestStruct ( ) , new TestStruct ( ) } } , false , 1 } ,
106
+ new object [ ] { new Dictionary < string , string > { { "test" , "string" } } , true , 1 } ,
107
+ new object [ ] { new Dictionary < string , object > { { "test" , "object" } } , true , 1 } ,
108
+ new object [ ] { new Dictionary < string , PriorityAttribute > { { "test" , new PriorityAttribute ( 1 ) } } , true , 1 } ,
109
+ new object [ ] { new Dictionary < string , Guid > { { "test" , Guid . Empty } } , true , 1 } ,
110
+ new object [ ] { new Dictionary < string , IData > { { "test" , new SimpleError ( ) } } , true , 1 } ,
111
+ new object [ ] { new Dictionary < string , TestEnum > { { "test" , TestEnum . None } } , true , 1 } ,
112
+ new object [ ] { new Dictionary < string , TestStruct > { { "test" , new TestStruct ( ) } } , true , 1 } ,
113
+ new object [ ] { new Dictionary < string , int > { { "test" , 1 } } , true , 1 } ,
114
+ new object [ ] { new Dictionary < string , bool > { { "test" , false } } , true , 1 }
115
+ } ;
116
+ }
117
+ }
118
+
119
+ [ Theory ]
120
+ [ MemberData ( "DifferentExceptionDataDictionaryTypes" ) ]
121
+ public void ErrorPlugin_CanProcessDifferentExceptionDataDictionaryTypes ( IDictionary data , bool canMarkAsProcessed , int processedDataItemCount ) {
122
+ var errorPlugins = new List < IEventPlugin > {
123
+ new ErrorPlugin ( ) ,
124
+ new SimpleErrorPlugin ( )
125
+ } ;
126
+
127
+ foreach ( var plugin in errorPlugins ) {
128
+ if ( data != null && data . Contains ( "@exceptionless" ) )
129
+ data . Remove ( "@exceptionless" ) ;
130
+
131
+ var exception = new MyApplicationException ( "Test" ) { SetsDataProperty = data } ;
132
+ var client = new ExceptionlessClient ( ) ;
133
+ client . Configuration . AddDataExclusions ( "SetsDataProperty" ) ;
134
+ var context = new EventPluginContext ( client , new Event ( ) ) ;
135
+ context . ContextData . SetException ( exception ) ;
136
+ plugin . Run ( context ) ;
137
+ Assert . False ( context . Cancel ) ;
138
+
139
+ Assert . Equal ( canMarkAsProcessed , exception . Data != null && exception . Data . Contains ( "@exceptionless" ) ) ;
140
+
141
+ IData error = context . Event . GetError ( ) as IData ?? context . Event . GetSimpleError ( ) ;
142
+ Assert . NotNull ( error ) ;
143
+ Assert . Equal ( processedDataItemCount , error . Data . Count ) ;
144
+ }
145
+ }
146
+
147
+ [ Fact ]
148
+ public void ErrorPlugin_CopyExceptionDataToRootErrorData ( ) {
149
+ var errorPlugins = new List < IEventPlugin > {
150
+ new ErrorPlugin ( ) ,
151
+ new SimpleErrorPlugin ( )
152
+ } ;
153
+
154
+ foreach ( var plugin in errorPlugins ) {
155
+ var exception = new MyApplicationException ( "Test" ) {
156
+ RandomValue = "Test" ,
157
+ SetsDataProperty = new Dictionary < object , string > {
158
+ { 1 , 1 . GetType ( ) . Name } ,
159
+ { "test" , "test" . GetType ( ) . Name } ,
160
+ { Guid . NewGuid ( ) , typeof ( Guid ) . Name } ,
161
+ { false , typeof ( bool ) . Name }
162
+ }
163
+ } ;
164
+
165
+ var client = new ExceptionlessClient ( ) ;
166
+ var context = new EventPluginContext ( client , new Event ( ) ) ;
167
+ context . ContextData . SetException ( exception ) ;
168
+ plugin . Run ( context ) ;
169
+ Assert . False ( context . Cancel ) ;
170
+
171
+ IData error = context . Event . GetError ( ) as IData ?? context . Event . GetSimpleError ( ) ;
172
+ Assert . NotNull ( error ) ;
173
+ Assert . Equal ( 5 , error . Data . Count ) ;
174
+ }
175
+ }
176
+
93
177
[ Fact ]
94
178
public void ErrorPlugin_IgnoredProperties ( ) {
95
179
var exception = new MyApplicationException ( "Test" ) {
@@ -336,13 +420,27 @@ public void Run(EventPluginContext context) {}
336
420
public class PluginWithPriority11 : IEventPlugin {
337
421
public void Run ( EventPluginContext context ) { }
338
422
}
423
+
424
+ private enum TestEnum {
425
+ None = 1
426
+ }
427
+
428
+ private struct TestStruct {
429
+ public int Id { get ; set ; }
430
+ }
339
431
340
432
public class MyApplicationException : ApplicationException {
341
- public MyApplicationException ( string message ) : base ( message ) { }
433
+ public MyApplicationException ( string message ) : base ( message ) {
434
+ SetsDataProperty = Data ;
435
+ }
342
436
343
437
public string IgnoredProperty { get ; set ; }
344
438
345
439
public string RandomValue { get ; set ; }
440
+
441
+ public IDictionary SetsDataProperty { get ; set ; }
442
+
443
+ public override IDictionary Data { get { return SetsDataProperty ; } }
346
444
}
347
445
}
348
446
}
0 commit comments