Is there a way in FluentAssertions to avoid the automatic object graph drilldown for .And
and .Which
cascades?
And some point of the drilldown I would like to go back to the root level and check the status code.
Small code example:
Func<Task> action = async () => await this.someContext.someResponseTask;
action.Should()
.Throw<SwaggerOpenApiException<IList<ApiValidationError>>>()
.Which.Result.Should().Contain(x => x.ErrorCode == errorCode)
.Which.ErrorDetails.Should().Contain(dictionaryWithParsedErrorDetails)
// NOTE: This does not work (compile) as it operates on "ErrorDetails",
// would like to access root level exception again.
.Which.StatusCode.Should().Be(HttpStatusCode.Conflict);
Obviously I could wrap await this.someContext.someResponseTask
into a try/catch and store the exception into a variable but this is not really an elegant way of doing this, especially with FluentAssertions at your fingertips.