@@ -299,17 +299,28 @@ public void Raise_custom_event_that_has_sender_and_args_but_does_not_inherit_fro
299
299
}
300
300
301
301
[ Test ]
302
- public void MyEvent_With_CustomEventArgsWithNonPublicDefaultConstructor_IsRaised ( )
302
+ public void MyEvent_with_CustomEventArgsWithInternalDefaultConstructor_is_raised ( )
303
303
{
304
304
// Arrange
305
- IExample mockExample = Substitute . For < IExample > ( ) ;
306
- var consumer = new Consumer ( mockExample ) ;
305
+ var exampleInternalMock = Substitute . For < IExampleInternal > ( ) ;
306
+ var consumerInternal = new ConsumerInternal ( exampleInternalMock ) ;
307
307
308
308
// Act
309
- mockExample . MyEvent += Raise . EventWith < CustomEventArgsWithInternalDefaultConstructor > ( this , null ! ) ;
309
+ exampleInternalMock . MyEvent += Raise . EventWith < CustomEventArgsWithInternalDefaultConstructor > ( this , null ! ) ;
310
310
311
311
// Assert
312
- Assert . That ( consumer . SomethingWasDone ) ;
312
+ Assert . That ( consumerInternal . SomethingWasDone ) ;
313
+ }
314
+
315
+ [ Test ]
316
+ public void MyEvent_with_CustomEventArgsWithPrivateDefaultConstructor_throws_CannotCreateEventArgsException ( )
317
+ {
318
+ // Arrange
319
+ var examplePrivateMock = Substitute . For < IExamplePrivate > ( ) ;
320
+
321
+ // Act and Assert
322
+ Assert . Throws < CannotCreateEventArgsException > ( ( ) =>
323
+ examplePrivateMock . MyEvent += Raise . EventWith < CustomEventArgsWithPrivateDefaultConstructor > ( this , null ! ) ) ;
313
324
}
314
325
315
326
class RaisedEventRecorder < T >
@@ -358,13 +369,13 @@ public class CustomEventArgsWithInternalDefaultConstructor : EventArgs
358
369
{
359
370
internal CustomEventArgsWithInternalDefaultConstructor ( ) { }
360
371
}
361
- public interface IExample
372
+ public interface IExampleInternal
362
373
{
363
374
public event EventHandler < CustomEventArgsWithInternalDefaultConstructor > MyEvent ;
364
375
}
365
- public class Consumer
376
+ public class ConsumerInternal
366
377
{
367
- public Consumer ( IExample example )
378
+ public ConsumerInternal ( IExampleInternal example )
368
379
{
369
380
example . MyEvent += OnMyEvent ;
370
381
}
@@ -378,4 +389,13 @@ private void DoSomething()
378
389
SomethingWasDone = true ;
379
390
}
380
391
}
392
+
393
+ public class CustomEventArgsWithPrivateDefaultConstructor : EventArgs
394
+ {
395
+ private CustomEventArgsWithPrivateDefaultConstructor ( ) { }
396
+ }
397
+ public interface IExamplePrivate
398
+ {
399
+ public event EventHandler < CustomEventArgsWithPrivateDefaultConstructor > MyEvent ;
400
+ }
381
401
}
0 commit comments