예제 #1
0
        protected void ConfigureItemResponse(string root = null)
        {
            HttpRequestMessage requestMessage = null;

            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .That.Matches(
                                    message => root == null || message.RequestUri.ToString().Contains("root=" + root)), A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options, CancellationToken token) =>
            {
                requestMessage = message;
            })
            .ReturnsLazily(() => GenerateItemResponse(requestMessage));

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .That.Matches(
                               message => root == null || message.RequestUri.ToString().Contains("root=" + root)), A <HttpCompletionOption> .Ignored))
            .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options) =>
            {
                requestMessage = message;
            })
            .ReturnsLazily(() => GenerateItemResponse(requestMessage));
        }
        protected HttpResponseMessage ExecuteRequest(HttpRequestMessage requestMessage, HttpCompletionOption httpCompletionOption)
        {
            var responseMessage = RequestExecutorFactory.GetSyncRequestExecutor()
                                  .Send(HttpClient, requestMessage, httpCompletionOption);

            ProcessCookiesForRuntime(responseMessage);

            return(responseMessage);
        }
예제 #3
0
        protected void ConfigureZoneUnavailableResponse()
        {
            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Returns(GenerateRedirectionUnavailableResponse());

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored))
            .Returns(GenerateRedirectionUnavailableResponse());
        }
예제 #4
0
        protected void ConfigureDomainChangedResponse(string root = null)
        {
            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Returns(GenerateRedirectionResponse(root));

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored))
            .Returns(GenerateRedirectionResponse(root));
        }
예제 #5
0
        protected void ConfigureAsyncOperationScheduled()
        {
            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Returns(GenerateAsyncOperationScheduled());

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored))
            .Returns(GenerateAsyncOperationScheduled());
        }
예제 #6
0
        protected void ConfigureStreamResponse(string responseContent)
        {
            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Returns(this.GenerateStreamResponse(responseContent));

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored))
            .Returns(this.GenerateStreamResponse(responseContent));
        }
예제 #7
0
        protected void ConfigureNotFound()
        {
            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Returns(GenerateODataRequestException(HttpStatusCode.NotFound, "Items: NotFound"));

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored))
            .Returns(GenerateODataRequestException(HttpStatusCode.NotFound, "Items: NotFound"));
        }
예제 #8
0
        internal void RegisterRequestProviders()
        {
            RequestProviderFactory = new RequestProviderFactory();

            RegisterSyncRequestProvider(() => new SyncRequestProvider(this));
            if (RequestExecutorFactory.GetSyncRequestExecutor() == null)
            {
                RequestExecutorFactory.RegisterSyncRequestProvider(new SyncRequestExecutor());
            }
#if ASYNC
            RegisterAsyncRequestProvider(() => new AsyncRequestProvider(this));
            if (RequestExecutorFactory.GetAsyncRequestExecutor() == null)
            {
                RequestExecutorFactory.RegisterAsyncRequestProvider(new AsyncRequestExecutor());
            }
#endif
        }
        protected HttpResponseMessage ExecuteRequest(HttpRequestMessage requestMessage, HttpCompletionOption httpCompletionOption, int redirectionCount = 0)
        {
            if (redirectionCount >= MaxAutomaticRedirections)
            {
                throw new HttpRequestException("Exceeded maximum number of allowed redirects.");
            }
            var responseMessage = (ShareFileClient.SyncRequestExecutor ?? RequestExecutorFactory.GetSyncRequestExecutor())
                                  .Send(HttpClient, requestMessage, httpCompletionOption);

            var redirect = responseMessage.GetSecureRedirect();

            if (redirect != null)
            {
                return(ExecuteRequest(requestMessage.Clone(redirect), httpCompletionOption, ++redirectionCount));
            }

            ProcessCookiesForRuntime(responseMessage);

            return(responseMessage);
        }
예제 #10
0
        protected void ConfigureUnauthorizedResponse()
        {
            HttpRequestMessage requestMessage = null;

            A.CallTo(() =>
                     RequestExecutorFactory.GetAsyncRequestExecutor()
                     .SendAsync(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored,
                                A <CancellationToken> .Ignored))
            .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options, CancellationToken token) =>
            {
                requestMessage = message;
            })
            .ReturnsLazily(() => GenerateUnauthorizedResponse(requestMessage));

            A.CallTo(() =>
                     RequestExecutorFactory.GetSyncRequestExecutor()
                     .Send(A <HttpClient> .Ignored, A <HttpRequestMessage> .Ignored, A <HttpCompletionOption> .Ignored))
            .Invokes((HttpClient client, HttpRequestMessage message, HttpCompletionOption options) =>
            {
                requestMessage = message;
            })
            .ReturnsLazily(() => GenerateUnauthorizedResponse(requestMessage));
        }