예제 #1
0
        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);
        }
예제 #2
0
            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);
            }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 public void AddToClient(AmazonServiceClient client)
 {
     MockHttpRequestFactory.AddToClient(client, this);
 }