Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-generic overload for WithInnerExceptionExactly #1632

Closed
lonix1 opened this issue Aug 3, 2021 · 1 comment · Fixed by #1769
Closed

Non-generic overload for WithInnerExceptionExactly #1632

lonix1 opened this issue Aug 3, 2021 · 1 comment · Fixed by #1769

Comments

@lonix1
Copy link

lonix1 commented Aug 3, 2021

Background

I can do this:

action.Should().Throw<TargetInvocationException>()
  .WithInnerExceptionExactly<TException>()         // <--- known at compile time
  .Where(x => x.Message == message)
  .And.ParamName.Should().Be(paramName);

Problem

The above assumes I know TException at compile time. But what if I don't?

I can rewrite it using a trick I learnt from @dennisdoomen, like this:

action.Should().Throw<TargetInvocationException>()
  .WithInnerException<Exception>().Which.Should().BeOfType(expectedType)
  //.Where(x => x.Message == message)
  //.And.ParamName.Should().Be(paramName);

But then I can't chain .Where etc.

Feature Request

I read the exception docs but couldn't find a workaround.

Please consider adding an overload that take an instance:

.WithInnerExceptionExactly(expectedType)

Versions

  • Which version of Fluent Assertions are you using? 5.10.3
  • Which .NET runtime and version are you targeting? 5.0.301
@dennisdoomen
Copy link
Member

Sure. If anybody is willing to contribute this, we would welcome it.

@dennisdoomen dennisdoomen changed the title [Feature Request] Non-generic overload for WithInnerExceptionExactly Non-generic overload for WithInnerExceptionExactly Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants