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); }
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()); }
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)); }
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()); }
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)); }
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")); }
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); }
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)); }