Skip to content

Commit ff792a2

Browse files
committed
explicit wrapped assert response exception rather then relying on AssertionScope which loses stack trace of the failed assertions (by design)
1 parent f398f16 commit ff792a2

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/Tests/Tests/Framework/EndpointTests/ApiIntegrationTestBase.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,32 @@ protected override Task AssertOnAllResponses(Action<TResponse> assert)
5050
if (TestClient.Configuration.RunIntegrationTests && !r.IsValid && r.ApiCall.OriginalException != null
5151
&& !(r.ApiCall.OriginalException is ElasticsearchClientException))
5252
{
53-
ExceptionDispatchInfo.Capture(r.ApiCall.OriginalException.Demystify()).Throw();
54-
return;
53+
var e = ExceptionDispatchInfo.Capture(r.ApiCall.OriginalException.Demystify());
54+
throw new ResponseAssertionException(e.SourceException, r);
5555
}
5656

57-
using (var scope = new AssertionScope())
57+
try
5858
{
5959
assert(r);
60-
var failures = scope.Discard();
61-
if (failures.Length <= 0) return;
62-
63-
var failure = failures[0];
64-
scope.AddReportable("Failure", failure);
65-
scope.AddReportable("DebugInformation", r.DebugInformation);
66-
scope.FailWith( $@"{{Failure}}
67-
Response Under Test:
68-
{{DebugInformation}}");
69-
60+
}
61+
catch (Exception e)
62+
{
63+
throw new ResponseAssertionException(e, r);
7064
}
7165
});
7266
}
7367
}
68+
69+
public class ResponseAssertionException : Exception
70+
{
71+
private readonly IResponse _response;
72+
73+
public ResponseAssertionException(Exception innerException, IResponse response)
74+
: base(ResponseInMessage(innerException.Message, response), innerException) =>
75+
_response = response;
76+
77+
private static string ResponseInMessage(string innerExceptionMessage, IResponse r) => $@"{innerExceptionMessage}
78+
Response Under Test:
79+
{r.DebugInformation}";
80+
}
7481
}

0 commit comments

Comments
 (0)