Skip to content

InnerException information missing in output when using Should().NotThrow() #2015

@rcdailey

Description

@rcdailey

I have a unit test that exercises dependency resolution in Autofac. The test itself is simple:

// This enumerator ensures that this test case is invoked once per registered concrete type
[TestCaseSource(typeof(ConcreteTypeEnumerator))]
public void Service_should_be_instantiable(Type service)
{
    // This just sets up all the registrations from my app in a reusable way
    using var container = new CompositionRoot().Setup().Container;
    var act = () => container.Resolve(service);
    act.Should().NotThrow();
}

Then a specific iteration of this test fails, I get the below, truncated output:

Did not expect any exception, but found Autofac.Core.DependencyResolutionException with message "An exception was thrown while activating Recyclarr.Command.Helpers.CacheStoragePath."
     at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)

Now change the above example to this:

[TestCaseSource(typeof(ConcreteTypeEnumerator))]
public void Service_should_be_instantiable(Type service)
{
    using var container = new CompositionRoot().Setup(RegisterAdditionalServices).Container;
    container.Resolve(service);
}

This will throw the same exception, except this time it goes to NUnit3 untouched instead of through FluentAssertions. You now get this output:

Autofac.Core.DependencyResolutionException : An exception was thrown while activating Recyclarr.Command.Helpers.CacheStoragePath.
Data:
  ActivatorChain: Recyclarr.Command.Helpers.CacheStoragePath
  ----> Autofac.Core.DependencyResolutionException : None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Recyclarr.Command.Helpers.CacheStoragePath' can be invoked with the available services and parameters:
Cannot resolve parameter 'Recyclarr.Command.IServiceCommand serviceCommand' of constructor 'Void .ctor(TrashLib.Startup.IAppPaths, Recyclarr.Command.IServiceCommand)'.
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)

As you can see, there's more detail in the second case. This additional detail is of particular importance for Autofac, because without it, I can't tell exactly why the resolution failed.

If I stop in the debugger, I see that DependencyResolutionException.InnerException seems to have the additional detail. But for some reason that's omitted and/or the exception output is truncated.

Please address the issue by ensuring that InnerException details are printed to the console in this case.

Versions:

  • Which version of Fluent Assertions are you using? 6.7.0
  • Which .NET runtime and version are you targeting? .NET 6

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