Esempio n. 1
0
        public void AssertJsonSerializer()
        {
            string connectionString    = "AccountEndpoint=https://localtestcosmos.documents.azure.com:443/;AccountKey=425Mcv8CXQqzRNCgFNjIhT424GK99CKJvASowTnq15Vt8LeahXTcN5wt3342vQ==;";
            var    cosmosClientBuilder = new CosmosClientBuilder(connectionString);
            var    cosmosClient        = cosmosClientBuilder.Build(new MockDocumentClient());

            Assert.IsInstanceOfType(cosmosClient.ClientOptions.CosmosSerializerWithWrapperOrDefault, typeof(CosmosJsonSerializerWrapper));
            Assert.AreEqual(cosmosClient.ClientOptions.CosmosSerializerWithWrapperOrDefault, cosmosClient.ClientOptions.PropertiesSerializer);

            CosmosSerializer defaultSerializer  = cosmosClient.ClientOptions.PropertiesSerializer;
            CosmosSerializer mockJsonSerializer = new Mock <CosmosSerializer>().Object;

            cosmosClientBuilder.WithCustomJsonSerializer(mockJsonSerializer);
            var cosmosClientCustom = cosmosClientBuilder.Build(new MockDocumentClient());

            Assert.AreEqual(defaultSerializer, cosmosClientCustom.ClientOptions.PropertiesSerializer);
            Assert.AreEqual(mockJsonSerializer, cosmosClientCustom.ClientOptions.Serializer);
            Assert.IsInstanceOfType(cosmosClientCustom.ClientOptions.CosmosSerializerWithWrapperOrDefault, typeof(CosmosJsonSerializerWrapper));
            Assert.AreEqual(mockJsonSerializer, ((CosmosJsonSerializerWrapper)cosmosClientCustom.ClientOptions.CosmosSerializerWithWrapperOrDefault).InternalJsonSerializer);
        }