@@ -193,6 +193,74 @@ public void PrivateInformation_WillNotUpdateIdentity() {
193
193
Assert . Equal ( "Blake" , user ? . Name ) ;
194
194
}
195
195
196
+
197
+ [ Fact ]
198
+ public void LazyLoadAndRemovePlugin ( ) {
199
+ var configuration = new ExceptionlessConfiguration ( DependencyResolver . Default ) ;
200
+ foreach ( var plugin in configuration . Plugins )
201
+ configuration . RemovePlugin ( plugin . Key ) ;
202
+
203
+ configuration . AddPlugin < ThrowIfInitializedTestPlugin > ( ) ;
204
+ configuration . RemovePlugin < ThrowIfInitializedTestPlugin > ( ) ;
205
+ }
206
+
207
+ private class ThrowIfInitializedTestPlugin : IEventPlugin , IDisposable {
208
+ public ThrowIfInitializedTestPlugin ( ) {
209
+ throw new ApplicationException ( "Plugin shouldn't be constructed" ) ;
210
+ }
211
+
212
+ public void Run ( EventPluginContext context ) { }
213
+
214
+ public void Dispose ( ) {
215
+ throw new ApplicationException ( "Plugin shouldn't be created or disposed" ) ;
216
+ }
217
+ }
218
+
219
+ [ Fact ]
220
+ public void CanDisposePlugin ( ) {
221
+ var configuration = new ExceptionlessConfiguration ( DependencyResolver . Default ) ;
222
+ foreach ( var plugin in configuration . Plugins )
223
+ configuration . RemovePlugin ( plugin . Key ) ;
224
+
225
+ Assert . Equal ( 0 , CounterTestPlugin . ConstructorCount ) ;
226
+ Assert . Equal ( 0 , CounterTestPlugin . RunCount ) ;
227
+ Assert . Equal ( 0 , CounterTestPlugin . DisposeCount ) ;
228
+
229
+ configuration . AddPlugin < CounterTestPlugin > ( ) ;
230
+ configuration . AddPlugin < CounterTestPlugin > ( ) ;
231
+
232
+ for ( int i = 0 ; i < 2 ; i ++ ) {
233
+ foreach ( var pluginRegistration in configuration . Plugins )
234
+ pluginRegistration . Plugin . Run ( new EventPluginContext ( new ExceptionlessClient ( ) , new Event ( ) ) ) ;
235
+ }
236
+
237
+ configuration . RemovePlugin < CounterTestPlugin > ( ) ;
238
+ configuration . RemovePlugin < CounterTestPlugin > ( ) ;
239
+
240
+
241
+ Assert . Equal ( 1 , CounterTestPlugin . ConstructorCount ) ;
242
+ Assert . Equal ( 2 , CounterTestPlugin . RunCount ) ;
243
+ Assert . Equal ( 1 , CounterTestPlugin . DisposeCount ) ;
244
+ }
245
+
246
+ public class CounterTestPlugin : IEventPlugin , IDisposable {
247
+ public static byte ConstructorCount = 0 ;
248
+ public static byte RunCount = 0 ;
249
+ public static byte DisposeCount = 0 ;
250
+
251
+ public CounterTestPlugin ( ) {
252
+ ConstructorCount ++ ;
253
+ }
254
+
255
+ public void Run ( EventPluginContext context ) {
256
+ RunCount ++ ;
257
+ }
258
+
259
+ public void Dispose ( ) {
260
+ DisposeCount ++ ;
261
+ }
262
+ }
263
+
196
264
[ Fact ]
197
265
public void VerifyPriority ( ) {
198
266
var config = new ExceptionlessConfiguration ( DependencyResolver . CreateDefault ( ) ) ;
0 commit comments