public void TestRedirectAsync() { var context = CreateAsyncTestContext(); Tester.Reset(); Tester.Action = (int callCount) => { if (callCount == 1) { throw new WebException("Redirect", null, WebExceptionStatus.Success, HttpWebResponseHelper.Create(HttpStatusCode.TemporaryRedirect, new WebHeaderCollection { { "location", RedirectLocation } })); } }; Tester.Validate = (int callCount) => { if (callCount == 2) { Assert.AreEqual(RedirectLocation, context.RequestContext.Request.Endpoint.AbsoluteUri); } }; var asyncResult = RuntimePipeline.InvokeAsync(context); asyncResult.AsyncWaitHandle.WaitOne(); Assert.AreEqual(2, Tester.CallCount); }
public async Task TestRedirectAsync() { var context = CreateTestContext(); var httpResponse = context.ResponseContext.HttpResponse; Tester.Reset(); Tester.Action2 = (callCount, executionContext) => { if (callCount == 1) { executionContext.ResponseContext.HttpResponse = new HttpWebRequestResponseData( HttpWebResponseHelper.Create(HttpStatusCode.TemporaryRedirect, new WebHeaderCollection { { "location", RedirectLocation } })); } else { executionContext.ResponseContext.HttpResponse = httpResponse; } }; Tester.Validate = (int callCount) => { if (callCount == 2) { Assert.AreEqual(RedirectLocation, context.RequestContext.Request.Endpoint.AbsoluteUri); } }; await RuntimePipeline.InvokeAsync <AmazonWebServiceResponse>(context); Assert.AreEqual(2, Tester.CallCount); }