private async Task <StepResult> HandleHttpResponseAsync(HttpWebRequest request, MessagingContext ctx)
        {
            Logger.Trace($"AS4Message received from: {request.Address}");
            (HttpWebResponse webResponse, WebException exception) =
                await _httpClient.Respond(request)
                .ConfigureAwait(false);

            if (webResponse != null &&
                ContentTypeSupporter.IsContentTypeSupported(webResponse.ContentType))
            {
                using (AS4Response res = await AS4Response.Create(ctx, webResponse).ConfigureAwait(false))
                {
                    SendResult result = SendResultUtils.DetermineSendResultFromHttpResonse(res.StatusCode);
                    await UpdateRetryStatusForMessageAsync(ctx, result);

                    var handler = new PullRequestResponseHandler(
                        _createDatastore,
                        new EmptyBodyResponseHandler(
                            new TailResponseHandler()));

                    return(await handler
                           .HandleResponse(res)
                           .ConfigureAwait(false));
                }
            }

            Logger.ErrorDeep(exception);
            throw new WebException($"Failed to Send AS4Message to Url: {request.RequestUri}.", exception);
        }
            public async Task HandlerStopsExecution_IfResponseIsWarning()
            {
                // Arrange
                IAS4Response stubAS4Response = await CreatePullRequestWarning();

                var sut = new PullRequestResponseHandler(() => null, CreateAnonymousNextHandler());

                // Act
                StepResult actualResult = await sut.HandleResponse(stubAS4Response);

                // Assert
                Assert.False(actualResult.CanProceed);
                AssertNoChangeInPModes(stubAS4Response, actualResult);
            }
            public async Task ThenNextHandlerGetsResponse_IfNotOriginatedFromPullRequest()
            {
                // Arrange
                AS4Response as4Response = CreateAnonymousAS4Response();

                var spyHandler = new SpyAS4ResponseHandler();
                var handler    = new PullRequestResponseHandler(() => null, spyHandler);

                // Act
                await handler.HandleResponse(as4Response);

                // Assert
                Assert.True(spyHandler.IsCalled);
            }
            public async Task ThenHandlerReturnsStoppedExecutionStepResult()
            {
                // Arrange
                IAS4Response stubAS4Response = CreateResponseWith(
                    request: new PullRequest($"pr-{Guid.NewGuid()}", "some-mpc"),
                    response: Error.CreatePullRequestWarning($"error-{Guid.NewGuid()}"));

                var handler = new PullRequestResponseHandler(() => null, CreateAnonymousNextHandler());

                // Act
                StepResult actualResult = await handler.HandleResponse(stubAS4Response);

                // Assert
                Assert.False(actualResult.CanProceed);
                AssertNoChangeInPModes(stubAS4Response, actualResult);
            }