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(); } }
protected virtual async Task WriteBody(TestContext ctx, CancellationToken cancellationToken) { using (var stream = await RequestExt.GetRequestStreamAsync().ConfigureAwait(false)) { await Content.WriteToAsync(ctx, stream, cancellationToken); } }