private static CosmosClientContext GetMockedClientContext(
            Func <RequestMessage, CancellationToken, Task <ResponseMessage> > handlerFunc)
        {
            CosmosClient client = MockCosmosUtil.CreateMockCosmosClient();

            Mock <PartitionRoutingHelper> partitionRoutingHelperMock = MockCosmosUtil.GetPartitionRoutingHelperMock("0");
            PartitionKeyRangeHandler      partitionKeyRangeHandler   = new PartitionKeyRangeHandler(client, partitionRoutingHelperMock.Object);

            TestHandler testHandler = new TestHandler(handlerFunc);

            partitionKeyRangeHandler.InnerHandler = testHandler;

            RequestHandler handler = client.RequestHandler.InnerHandler;

            while (handler != null)
            {
                if (handler.InnerHandler is RouterHandler)
                {
                    handler.InnerHandler = new RouterHandler(partitionKeyRangeHandler, 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()));
        }
        private static CosmosClientContext GetMockedClientContext(
            Func <RequestMessage, CancellationToken, Task <ResponseMessage> > handlerFunc)
        {
            CosmosClient        client        = MockCosmosUtil.CreateMockCosmosClient();
            CosmosClientContext clientContext = ClientContextCore.Create(
                client,
                new MockDocumentClient(),
                new CosmosClientOptions());

            Mock <PartitionRoutingHelper> partitionRoutingHelperMock = MockCosmosUtil.GetPartitionRoutingHelperMock("0");
            PartitionKeyRangeHandler      partitionKeyRangeHandler   = new PartitionKeyRangeHandler(client, partitionRoutingHelperMock.Object);

            TestHandler testHandler = new TestHandler(handlerFunc);

            partitionKeyRangeHandler.InnerHandler = testHandler;

            RequestHandler handler = clientContext.RequestHandler.InnerHandler;

            while (handler != null)
            {
                if (handler.InnerHandler is RouterHandler)
                {
                    handler.InnerHandler = new RouterHandler(partitionKeyRangeHandler, testHandler);
                    break;
                }

                handler = handler.InnerHandler;
            }

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