public async Task  TestJsonSerializerSettings(bool useGateway)
        {
            CosmosClient cosmosClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) => {
                if (useGateway)
                {
                    cosmosClientBuilder.WithCustomSerializer(new CustomJsonSerializer(CustomSerializationTests.GetSerializerWithCustomConverterAndBinder())).WithConnectionModeGateway();
                }
                else
                {
                    cosmosClientBuilder.WithCustomSerializer(new CustomJsonSerializer(CustomSerializationTests.GetSerializerWithCustomConverterAndBinder())).WithConnectionModeDirect();
                }
            });
            Container container = cosmosClient.GetContainer(this.databaseName, this.partitionedCollectionName);

            Random rnd = new Random();

            byte[] bytes = new byte[100];
            rnd.NextBytes(bytes);
            TestDocument testDocument = new TestDocument(new KerberosTicketHashKey(bytes));

            //create and read
            ItemResponse <TestDocument> createResponse = await container.CreateItemAsync <TestDocument>(testDocument);

            ItemResponse <TestDocument> readResponse = await container.ReadItemAsync <TestDocument>(testDocument.Id, new Cosmos.PartitionKey(testDocument.Name));

            this.AssertEqual(testDocument, readResponse.Resource);
            this.AssertEqual(testDocument, createResponse.Resource);

            // upsert
            ItemResponse <TestDocument> upsertResponse = await container.UpsertItemAsync <TestDocument>(testDocument);

            readResponse = await container.ReadItemAsync <TestDocument>(testDocument.Id, new Cosmos.PartitionKey(testDocument.Name));

            this.AssertEqual(testDocument, readResponse.Resource);
            this.AssertEqual(testDocument, upsertResponse.Resource);

            // replace
            ItemResponse <TestDocument> replacedResponse = await container.ReplaceItemAsync <TestDocument>(testDocument, testDocument.Id);

            readResponse = await container.ReadItemAsync <TestDocument>(testDocument.Id, new Cosmos.PartitionKey(testDocument.Name));

            this.AssertEqual(testDocument, readResponse.Resource);
            this.AssertEqual(testDocument, replacedResponse.Resource);

            QueryDefinition             sql          = new QueryDefinition("select * from r");
            FeedIterator <TestDocument> feedIterator =
                container.GetItemQueryIterator <TestDocument>(queryDefinition: sql, requestOptions: new QueryRequestOptions()
            {
                MaxItemCount = 1
            });

            List <TestDocument> allDocuments = new List <TestDocument>();

            while (feedIterator.HasMoreResults)
            {
                allDocuments.AddRange(await feedIterator.ReadNextAsync());
            }

            this.AssertEqual(testDocument, allDocuments.First());

            //Will add LINQ test once it is available with new V3 OM
            // // LINQ Lambda
            // var query1 = client.CreateDocumentQuery<TestDocument>(partitionedCollectionUri, options)
            //            .Where(_ => _.Id.CompareTo(String.Empty) > 0)
            //            .Select(_ => _.Id);
            // string query1Str = query1.ToString();
            // var result = query1.ToList();
            // Assert.AreEqual(1, result.Count);
            // Assert.AreEqual(testDocument.Id, result[0]);

            // // LINQ Query
            // var query2 =
            //     from f in client.CreateDocumentQuery<TestDocument>(partitionedCollectionUri, options)
            //     where f.Id.CompareTo(String.Empty) > 0
            //     select f.Id;
            // string query2Str = query2.ToString();
            // var result2 = query2.ToList();
            // Assert.AreEqual(1, result2.Count);
            // Assert.AreEqual(testDocument.Id, result2[0]);
        }
        public void TestJsonSerializerSettings()
        {
            ConnectionMode connectionMode   = ConnectionMode.Gateway;
            var            connectionPolicy = new ConnectionPolicy()
            {
                ConnectionMode = connectionMode
            };
            var client = new DocumentClient(this.hostUri, this.masterKey, CustomSerializationTests.GetSerializerWithCustomConverterAndBinder(), connectionPolicy, ConsistencyLevel.Session);

            var rnd   = new Random();
            var bytes = new byte[100];

            rnd.NextBytes(bytes);
            var testDocument = new TestDocument(new KerberosTicketHashKey(bytes));

            Uri testDocumentUri = UriFactory.CreateDocumentUri(databaseName, collectionName, testDocument.Id);

            // create and read
            var createDocument = (TestDocument)(dynamic)client.CreateDocumentAsync(collectionUri, testDocument, disableAutomaticIdGeneration: true).Result.Resource;
            var readDocument   = client.ReadDocumentAsync <TestDocument>(testDocumentUri).Result.Document;

            AssertEqual(testDocument, readDocument);
            AssertEqual(testDocument, createDocument);

            // upsert
            var upsertedDocument = (TestDocument)(dynamic)client.UpsertDocumentAsync(collectionUri, testDocument, disableAutomaticIdGeneration: true).Result.Resource;

            readDocument = client.ReadDocumentAsync <TestDocument>(testDocumentUri).Result.Document;
            AssertEqual(testDocument, readDocument);
            AssertEqual(testDocument, upsertedDocument);

            // replace
            var replacedDocument = (TestDocument)(dynamic)client.ReplaceDocumentAsync(testDocumentUri, testDocument).Result.Resource;

            readDocument = client.ReadDocumentAsync <TestDocument>(testDocumentUri).Result.Document;
            AssertEqual(testDocument, readDocument);
            AssertEqual(testDocument, replacedDocument);

            // query
            readDocument = client.CreateDocumentQuery <TestDocument>(
                collectionUri,
                new FeedOptions
            {
                EnableCrossPartitionQuery = true,
                MaxDegreeOfParallelism    = -1,
                MaxBufferedItemCount      = -1
            }).ToList()[0];
            AssertEqual(testDocument, readDocument);

            // LINQ Lambda
            var query1 = client.CreateDocumentQuery <TestDocument>(collectionUri)
                         .Where(_ => _.Id.CompareTo(String.Empty) > 0)
                         .Select(_ => _.Id);
            string query1Str = query1.ToString();
            var    result    = query1.ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(testDocument.Id, result[0]);

            // LINQ Query
            var query2 =
                from f in client.CreateDocumentQuery <TestDocument>(collectionUri)
                where f.Id.CompareTo(String.Empty) > 0
                select f.Id;
            string query2Str = query2.ToString();
            var    result2   = query2.ToList();

            Assert.AreEqual(1, result2.Count);
            Assert.AreEqual(testDocument.Id, result2[0]);
        }