File tree 3 files changed +15
-1
lines changed
3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
19
19
* ` AmbiguousMatchException ` raised when interface has property indexer besides property in VB. (@mujdatdinc , #1129 )
20
20
* Interface default methods are ignored (@hahn-kev , #972 )
21
21
* Callback validation too strict when setting up a task's ` .Result ` property (@stakx , #1132 )
22
+ * ` setup.Returns(InvocationFunc) ` wraps thrown exceptions in ` TargetInvocationException ` (@stakx , #1141 )
22
23
23
24
24
25
## 4.16.0 (2021-01-16)
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ public void SetReturnComputedValueBehavior(Delegate valueFactory)
247
247
}
248
248
else if ( IsInvocationFunc ( valueFactory ) )
249
249
{
250
- this . returnOrThrow = new ReturnComputedValue ( invocation => valueFactory . DynamicInvoke ( invocation ) ) ;
250
+ this . returnOrThrow = new ReturnComputedValue ( invocation => valueFactory . InvokePreserveStack ( new object [ ] { invocation } ) ) ;
251
251
}
252
252
else
253
253
{
Original file line number Diff line number Diff line change @@ -516,6 +516,19 @@ public void CallbackWithMultipleArgumentIndexerSetterWithoutAny()
516
516
Assert . Equal ( 2 , result ) ;
517
517
}
518
518
519
+ [ Fact ]
520
+ public void Type_of_exception_thrown_from_InvocationFunc_callback_should_be_preserved ( )
521
+ {
522
+ var mock = new Mock < IFoo > ( ) ;
523
+ mock . Setup ( m => m . Submit ( "good" , "bad" ) ) . Returns ( new InvocationFunc ( invocation =>
524
+ {
525
+ throw new Exception ( "very bad" ) ; // this used to be erroneously wrapped as a `TargetInvocationException`
526
+ } ) ) ;
527
+
528
+ var ex = Assert . Throws < Exception > ( ( ) => mock . Object . Submit ( "good" , "bad" ) ) ;
529
+ Assert . Equal ( "very bad" , ex . Message ) ;
530
+ }
531
+
519
532
public interface IInterface
520
533
{
521
534
void Method ( Derived b ) ;
You can’t perform that action at this time.
0 commit comments