public void ValidateSerialization()
        {
            CosmosJsonSerializerCore jsonSerializer    = new CosmosJsonSerializerCore();
            ContainerProperties      containerSettings = new ContainerProperties("TestContainer", "/partitionKey");
            Stream basic = jsonSerializer.ToStream <ContainerProperties>(containerSettings);
            ContainerProperties response = jsonSerializer.FromStream <ContainerProperties>(basic);

            Assert.AreEqual(containerSettings.Id, response.Id);
            Assert.AreEqual(containerSettings.PartitionKeyPath, response.PartitionKeyPath);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the content of the Conflict resource in the Azure Cosmos DB service.
        /// </summary>
        /// <typeparam name="T">The type to use to deserialize the content.</typeparam>
        /// <param name="cosmosJsonSerializer">(Optional) <see cref="CosmosJsonSerializer"/> to use while parsing the content.</param>
        /// <returns>An instance of T</returns>
        public virtual T GetResource <T>(CosmosJsonSerializer cosmosJsonSerializer = null)
        {
            if (!string.IsNullOrEmpty(this.Content))
            {
                if (cosmosJsonSerializer == null)
                {
                    cosmosJsonSerializer = new CosmosJsonSerializerCore();
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(this.Content);
                        writer.Flush();
                        stream.Position = 0;
                        return(cosmosJsonSerializer.FromStream <T>(stream));
                    }
                }
            }

            return(default(T));
        }