Skip to content

Commit

Permalink
Merge pull request #1544 from thomaslevesque/dont-wrap-exception-in-i…
Browse files Browse the repository at this point in the history
…nvokes

Dont wrap exception in invokes
  • Loading branch information
blairconrad committed Dec 13, 2018
2 parents 5d3f169 + a9a07bf commit 8a3aafc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
9 changes: 1 addition & 8 deletions src/FakeItEasy/Configuration/BuildableCallRule.cs
Expand Up @@ -102,14 +102,7 @@ public virtual void Apply(IInterceptedFakeObjectCall fakeObjectCall)

foreach (var action in this.Actions)
{
try
{
action.Invoke(fakeObjectCall);
}
catch (Exception ex) when (!(ex is FakeConfigurationException))
{
throw new UserCallbackException(ExceptionMessages.UserCallbackThrewAnException("Callback"), ex);
}
action.Invoke(fakeObjectCall);
}

this.applicator.Invoke(fakeObjectCall);
Expand Down
12 changes: 3 additions & 9 deletions tests/FakeItEasy.Specs/UserCallbackExceptionSpecs.cs
Expand Up @@ -362,7 +362,7 @@ public void ExceptionInExceptionFactory(IFoo fake, Exception exception)
}

[Scenario]
public void ExceptionInCallback(IFoo fake, Exception exception)
public void ExceptionInCallbackIsNotWrapped(IFoo fake, Exception exception)
{
"Given a fake"
.x(() => fake = A.Fake<IFoo>());
Expand All @@ -373,14 +373,8 @@ public void ExceptionInCallback(IFoo fake, Exception exception)
"When the configured method is called"
.x(() => exception = Record.Exception(() => fake.Bar(0)));

"Then a UserCallbackException should be thrown"
.x(() => exception.Should().BeAnExceptionOfType<UserCallbackException>());

"And its message should describe where the exception was thrown from"
.x(() => exception.Message.Should().Be("Callback threw an exception. See inner exception for details."));

"And the inner exception should be the original exception"
.x(() => exception.InnerException.Should().BeAnExceptionOfType<MyException>().Which.Message.Should().Be("Oops"));
"Then the original exception should be thrown"
.x(() => exception.Should().BeAnExceptionOfType<MyException>().Which.Message.Should().Be("Oops"));
}

private static bool ThrowException()
Expand Down

0 comments on commit 8a3aafc

Please sign in to comment.