Exemplo n.º 1
0
        public override async Task <Response> SendAsync(TestContext ctx, CancellationToken cancellationToken)
        {
            var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            cts.Token.Register(() => Request.Abort());

            try {
                if (Content != null)
                {
                    using (var stream = await RequestExt.GetRequestStreamAsync()) {
                        using (var writer = new StreamWriter(stream)) {
                            await Content.WriteToAsync(writer);

                            await writer.FlushAsync();
                        }
                    }
                }

                var response = await RequestExt.GetResponseAsync();

                return(await GetResponseFromHttp(ctx, response, null, cancellationToken));
            } catch (WebException wexc) {
                var response = (HttpWebResponse)wexc.Response;
                if (response == null)
                {
                    return(new SimpleResponse(this, HttpStatusCode.InternalServerError, null, wexc));
                }

                return(GetResponseFromHttpSync(ctx, response, wexc));
            } catch (Exception ex) {
                return(new SimpleResponse(this, HttpStatusCode.InternalServerError, null, ex));
            } finally {
                cts.Dispose();
            }
        }
Exemplo n.º 2
0
        public override async Task <Response> SendAsync(TestContext ctx, CancellationToken cancellationToken)
        {
            var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            cts.Token.Register(() => Request.Abort());

            try {
                if (Content != null)
                {
                    await WriteBody(ctx, cancellationToken).ConfigureAwait(false);
                }

                var response = await RequestExt.GetResponseAsync().ConfigureAwait(false);

                return(await GetResponseFromHttp(ctx, response, null, cancellationToken));
            } catch (WebException wexc) {
                var response = (HttpWebResponse)wexc.Response;
                if (response == null)
                {
                    return(new SimpleResponse(this, HttpStatusCode.InternalServerError, null, wexc));
                }

                return(await GetResponseFromHttp(ctx, response, wexc, cancellationToken));
            } catch (Exception ex) {
                return(new SimpleResponse(this, HttpStatusCode.InternalServerError, null, ex));
            } finally {
                cts.Dispose();
            }
        }