Skip to content

Non-generic overload for WithInnerExceptionExactly #1632

@lonix1

Description

@lonix1

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions