public void TestErrorAsyncCall() { var factory = new MockHttpRequestFactory { GetResponseAction = () => { throw new IOException(); } }; var httpHandler = new HttpHandler <Stream>(factory, callbackSender); var runtimePipeline = new RuntimePipeline(httpHandler); var executionContext = CreateAsyncExecutionContextForListBuckets(); var asyncResult = httpHandler.InvokeAsync(executionContext); asyncResult.AsyncWaitHandle.WaitOne(); Assert.IsNotNull(executionContext.ResponseContext.AsyncResult.Exception); Assert.IsInstanceOfType(executionContext.ResponseContext.AsyncResult.Exception, typeof(IOException)); var httpRequest = factory.LastCreatedRequest; Assert.AreEqual("GET", httpRequest.Method); Assert.IsTrue(httpRequest.IsConfigureRequestCalled); Assert.IsTrue(httpRequest.IsSetRequestHeadersCalled); Assert.IsTrue(httpRequest.IsDisposed); Assert.IsTrue(httpRequest.IsAborted); }
public static void AddToClient(AmazonServiceClient client, Mocker mocker) { var pipeline = client .GetType() .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .GetValue(client, null) as RuntimePipeline; var requestFactory = new MockHttpRequestFactory(mocker); var httpHandler = new HttpHandler <Stream>(requestFactory, client); pipeline.ReplaceHandler <HttpHandler <Stream> >(httpHandler); }
public async Task TestSuccessfulAsyncCall() { var factory = new MockHttpRequestFactory(); var httpHandler = new HttpHandler <Stream>(factory, callbackSender); var runtimePipeline = new RuntimePipeline(httpHandler); var listBucketsRequest = new ListBucketsRequest(); var executionContext = CreateExecutionContextForListBuckets(); await httpHandler.InvokeAsync <ListBucketsResponse>(executionContext); Assert.IsNotNull(executionContext.ResponseContext.HttpResponse); var httpRequest = factory.LastCreatedRequest; Assert.AreEqual("GET", httpRequest.Method); Assert.IsTrue(httpRequest.IsConfigureRequestCalled); Assert.IsTrue(httpRequest.IsSetRequestHeadersCalled); Assert.IsTrue(httpRequest.IsDisposed); Assert.IsFalse(httpRequest.IsAborted); }
public void TestErrorCall() { var factory = new MockHttpRequestFactory { GetResponseAction = () => { throw new IOException(); } }; var httpHandler = new HttpHandler <Stream>(factory, callbackSender); var runtimePipeline = new RuntimePipeline(httpHandler); var executionContext = CreateExecutionContextForListBuckets(); Utils.AssertExceptionExpected(() => { httpHandler.InvokeSync(executionContext); }, typeof(IOException)); var httpRequest = factory.LastCreatedRequest; Assert.AreEqual("GET", httpRequest.Method); Assert.IsTrue(httpRequest.IsConfigureRequestCalled); Assert.IsTrue(httpRequest.IsSetRequestHeadersCalled); Assert.IsTrue(httpRequest.IsDisposed); }
public async Task TestErrorAsyncCall() { var factory = new MockHttpRequestFactory { GetResponseAction = () => { throw new IOException(); } }; var httpHandler = new HttpHandler <Stream>(factory, callbackSender); var runtimePipeline = new RuntimePipeline(httpHandler); var executionContext = CreateExecutionContextForListBuckets(); await Utils.AssertExceptionExpectedAsync(() => { return(httpHandler.InvokeAsync <AmazonWebServiceResponse>(executionContext)); }, typeof(IOException)); var httpRequest = factory.LastCreatedRequest; Assert.AreEqual("GET", httpRequest.Method); Assert.IsTrue(httpRequest.IsConfigureRequestCalled); Assert.IsTrue(httpRequest.IsSetRequestHeadersCalled); Assert.IsTrue(httpRequest.IsDisposed); Assert.IsTrue(httpRequest.IsAborted); }
public void AddToClient(AmazonServiceClient client) { MockHttpRequestFactory.AddToClient(client, this); }