public IClientPipeline CreatePipeline(Func<ActionDelegate<ClientActionContext>, ClientActionContext, Task> next = null) { ClientPipelineBuilder builder = new ClientPipelineBuilder(); builder.Use(new SessionMiddleware(SessionHandler.Object, SessionErrorHandling.Object)); if (next != null) { builder.Use(next); } return builder.BuildClient(); }
public IClientPipeline CreatePipeline(int retries) { ClientPipelineBuilder builder = new ClientPipelineBuilder(); builder.Use(new RetryRequestMiddleware(ErrorHandling.Object) { Retries = retries }); builder.Use( (next, ctxt) => { Callback.Object.Handle(ctxt); return(next(ctxt)); }); return(builder.BuildClient()); }
public virtual IClientPipeline BuildPipeline() { if (_serverProvider == null) { throw new InvalidOperationException("Server provider or target url was not configured."); } ClientPipelineBuilder context = new ClientPipelineBuilder(); context.Use(new ValidateProxyMiddleware()); if (_retryRequest != null) { context.Use(_retryRequest); } else if (_configuration.ErrorHandling != null) { context.Use(new ErrorHandlingMiddleware(_configuration.ErrorHandling)); } if (_sessionMiddleware != null) { context.Use(_sessionMiddleware); } if (_streamingMiddleware != null) { context.Use(_streamingMiddleware); } context.Use(new SerializationMiddleware(_configuration.Serializer, _configuration.ExceptionSerializer, _configuration.ErrorProvider)); context.Use(new PickConnectionMiddleware(_serverProvider, _configuration.EndpointProvider)); foreach (IMiddleware <ClientActionContext> middleware in _beforeSend) { context.Use(middleware); } context.Use( new CommunicationMiddleware(_messageHandler ?? _configuration.HttpMessageHandler ?? new HttpClientHandler()) { ResponseTimeout = _timeout ?? _configuration.DefaultResponseTimeout, TimeoutProvider = _timeoutProvider ?? _configuration.TimeoutProvider }); return((IClientPipeline)context.Build()); }
private static CosmosClientContext GetMockedClientContext( Func <RequestMessage, CancellationToken, Task <ResponseMessage> > handlerFunc) { CosmosClient client = MockCosmosUtil.CreateMockCosmosClient(); Mock <PartitionRoutingHelper> partitionRoutingHelperMock = MockCosmosUtil.GetPartitionRoutingHelperMock("0"); TestHandler testHandler = new TestHandler(handlerFunc); // Similar to FeedPipeline but with replaced transport RequestHandler[] feedPipeline = new RequestHandler[] { new NamedCacheRetryHandler(), new PartitionKeyRangeHandler(client), testHandler, }; RequestHandler feedHandler = ClientPipelineBuilder.CreatePipeline(feedPipeline); RequestHandler handler = client.RequestHandler.InnerHandler; while (handler != null) { if (handler.InnerHandler is RouterHandler) { handler.InnerHandler = new RouterHandler(feedHandler, testHandler); break; } handler = handler.InnerHandler; } CosmosResponseFactory responseFactory = new CosmosResponseFactory(MockCosmosUtil.Serializer); return(new ClientContextCore( client: client, clientOptions: new CosmosClientOptions(), serializerCore: MockCosmosUtil.Serializer, cosmosResponseFactory: responseFactory, requestHandler: client.RequestHandler, documentClient: new MockDocumentClient(), userAgent: null)); }
public IClientPipeline CreatePipeline(int retries) { ClientPipelineBuilder builder = new ClientPipelineBuilder(); builder.Use(new RetryRequestMiddleware(ErrorHandling.Object) {Retries = retries}); builder.Use( (next, ctxt) => { Callback.Object.Handle(ctxt); return next(ctxt); }); return builder.BuildClient(); }