You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I upgraded FakeItEasy from 2.3.1 to 4.9.1 and I have the following issue.
Scenario:
A Fake is configured to throw
Another Fake is configured to indirectly call the throwing fake
The exception from the first Fake is catched
Another exception is thrown in the catch block
Expected behaviour:
The exception thrown in the catch block is raised to the caller
Observed behaviour:
An UserCallbackException is raised to the caller
Workarounds:
Unpack the UserCallbackException and assert it's InnerException
Use a manually written Fake for the throwing interface
This behaviour seems to have been introduced with #1364
Is this behaviour intended, and is there a way to configure it, or do I have to use one of the workarounds?
FakeItEasy version: 4.9.1, also happens in 5.0.0-alpha.1
.NET Framework version: 4.7.2
Minimal repro:
[TestClass]publicclassUserCallbackExceptionTest{publicclassCatchedException:Exception{}publicclassThrowedException:Exception{}publicinterfaceIThrows{voidThrowIt();}publicinterfaceIDoStuff{voidExecute(Actionoperation);}publicclassUnderTest{privatereadonlyIThrows_throws;privatereadonlyIDoStuff_dostuff;publicUnderTest(IThrowsthrows,IDoStuffdostuff){_throws=throws;_dostuff=dostuff;}publicvoidDoStuff(){
_dostuff.Execute(DoStuffPrivately);}privatevoidDoStuffPrivately(){try{
_throws.ThrowIt();}catch(CatchedException){thrownew ThrowedException();}}}publicclassHandWrittenFakeDoStuff:IDoStuff{publicvoidExecute(Actionoperation){
operation();}}[TestMethod]publicvoidWorksWhenUsingHandWrittenFake(){IThrowsthrows= A.Fake<IThrows>();
A.CallTo(()=> throws.ThrowIt()).Throws(new CatchedException());UnderTestunderTest=new UnderTest(throws,new HandWrittenFakeDoStuff());
Assert.ThrowsException<ThrowedException>(()=> underTest.DoStuff());}[TestMethod]publicvoidDoesNotWorkWhenUsingFakeItEasyFake(){IDoStuffdoStuff= A.Fake<IDoStuff>();
A.CallTo(()=> doStuff.Execute(A<Action>.Ignored)).Invokes(call =>{// assume the real implementation does other things beside calling the action// to avoid those sideeffects we fake itActionoperation= call.GetArgument<Action>(0); operation();});IThrowsthrows= A.Fake<IThrows>();
A.CallTo(()=> throws.ThrowIt()).Throws(new CatchedException());UnderTestunderTest=new UnderTest(throws, doStuff);
Assert.ThrowsException<ThrowedException>(()=> underTest.DoStuff());}}
The text was updated successfully, but these errors were encountered:
Thanks for reporting this. At first glance, it looks like it's working as designed, but I see how this can be a problem in your case. Basically, starting with #1364, we wrap exceptions that occur in user callbacks, but in retrospect it might not be the right thing to do for Invokes. The callback specified in Invokes actually stands for the body of the faked method, so it could legitimately do anything the method body could do, including throwing an exception.
I upgraded FakeItEasy from 2.3.1 to 4.9.1 and I have the following issue.
Scenario:
Expected behaviour:
The exception thrown in the catch block is raised to the caller
Observed behaviour:
An UserCallbackException is raised to the caller
Workarounds:
This behaviour seems to have been introduced with #1364
Is this behaviour intended, and is there a way to configure it, or do I have to use one of the workarounds?
FakeItEasy version: 4.9.1, also happens in 5.0.0-alpha.1
.NET Framework version: 4.7.2
Minimal repro:
The text was updated successfully, but these errors were encountered: