From c8beda1b6f357e484346777fbc05a0058a08cdf7 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Thu, 9 Sep 2021 21:35:53 +0530 Subject: [PATCH] Add additional property for few more properties --- .../ClientEncryptionKeyProperties.cs | 39 ++++ .../OfferAutoscaleAutoUpgradeProperties.cs | 10 + .../Offer/OfferAutoscaleProperties.cs | 9 + .../Resource/Offer/OfferContentProperties.cs | 9 + .../Settings/BoundingBoxProperties.cs | 9 + .../Resource/Settings/PermissionProperties.cs | 9 + .../Resource/Settings/ThroughputProperties.cs | 9 + .../Resource/Settings/TriggerProperties.cs | 9 + .../Settings/UserDefinedFunctionProperties.cs | 9 + .../src/Resource/Settings/UserProperties.cs | 9 + .../SettingsContractTests.cs | 171 +++++++++++++++--- 11 files changed, 263 insertions(+), 29 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/ClientEncryptionKey/ClientEncryptionKeyProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/ClientEncryptionKey/ClientEncryptionKeyProperties.cs index d5c6cb0147..450403bb23 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/ClientEncryptionKey/ClientEncryptionKeyProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/ClientEncryptionKey/ClientEncryptionKeyProperties.cs @@ -9,6 +9,7 @@ namespace Microsoft.Azure.Cosmos using System.Linq; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; /// /// Details of an encryption key for use with the Azure Cosmos DB service. @@ -61,6 +62,7 @@ internal ClientEncryptionKeyProperties(ClientEncryptionKeyProperties source) this.WrappedDataEncryptionKey = new byte[source.WrappedDataEncryptionKey.Length]; source.WrappedDataEncryptionKey.CopyTo(this.WrappedDataEncryptionKey, index: 0); } + this.AdditionalProperties = source.AdditionalProperties; } /// @@ -148,6 +150,13 @@ internal ClientEncryptionKeyProperties(ClientEncryptionKeyProperties source) [JsonProperty(PropertyName = Constants.Properties.RId, NullValueHandling = NullValueHandling.Ignore)] internal string ResourceId { get; set; } + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + /// /// Compares this instance of client encryption key properties to another object. /// @@ -170,6 +179,8 @@ public bool Equals(ClientEncryptionKeyProperties other) this.EncryptionAlgorithm == other.EncryptionAlgorithm && ClientEncryptionKeyProperties.Equals(this.WrappedDataEncryptionKey, other.WrappedDataEncryptionKey) && EqualityComparer.Default.Equals(this.EncryptionKeyWrapMetadata, other.EncryptionKeyWrapMetadata) && + this.AdditionalProperties != null && other.AdditionalProperties != null && + this.CompareDictionary(this.AdditionalProperties, other.AdditionalProperties) && this.CreatedTime == other.CreatedTime && this.ETag == other.ETag && this.LastModified == other.LastModified && @@ -177,6 +188,34 @@ public bool Equals(ClientEncryptionKeyProperties other) this.ResourceId == other.ResourceId; } + private bool CompareDictionary(IDictionary dict1, IDictionary dict2) + { + bool isEqual = false; + if (dict1.Count == dict2.Count) + { + isEqual = true; + foreach (KeyValuePair pair in dict1) + { + if (dict2.TryGetValue(pair.Key, out JToken value)) + { + // Require value be equal. + if (!value.ToString().Equals(pair.Value.ToString())) + { + isEqual = false; + break; + } + } + else + { + // Require key be present. + isEqual = false; + break; + } + } + } + return isEqual; + } + /// /// Gets a hash code for the properties of this instance to optimize comparisons. /// diff --git a/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleAutoUpgradeProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleAutoUpgradeProperties.cs index 2ac915e196..be64e58209 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleAutoUpgradeProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleAutoUpgradeProperties.cs @@ -4,8 +4,10 @@ namespace Microsoft.Azure.Cosmos { + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; internal sealed class OfferAutoscaleAutoUpgradeProperties { @@ -25,6 +27,13 @@ internal OfferAutoscaleAutoUpgradeProperties(int incrementPercent) [JsonProperty(PropertyName = Constants.Properties.AutopilotThroughputPolicy, NullValueHandling = NullValueHandling.Ignore)] public AutoscaleThroughputProperties ThroughputProperties { get; private set; } + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + internal string GetJsonString() { return JsonConvert.SerializeObject(this, Formatting.None); @@ -39,6 +48,7 @@ public AutoscaleThroughputProperties(int incrementPercent) [JsonProperty(PropertyName = Constants.Properties.AutopilotThroughputPolicyIncrementPercent, NullValueHandling = NullValueHandling.Ignore)] public int IncrementPercent { get; private set; } + } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleProperties.cs index d5c2439973..a4d99af8ce 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferAutoscaleProperties.cs @@ -4,8 +4,10 @@ namespace Microsoft.Azure.Cosmos { + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; internal sealed class OfferAutoscaleProperties { @@ -39,6 +41,13 @@ internal OfferAutoscaleProperties( [JsonProperty(PropertyName = Constants.Properties.AutopilotAutoUpgradePolicy, NullValueHandling = NullValueHandling.Ignore)] public OfferAutoscaleAutoUpgradeProperties AutoscaleAutoUpgradeProperties { get; private set; } + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + internal string GetJsonString() { return JsonConvert.SerializeObject(this, Formatting.None); diff --git a/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferContentProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferContentProperties.cs index c4de03a3e2..41776992b1 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferContentProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Offer/OfferContentProperties.cs @@ -5,8 +5,10 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; internal sealed class OfferContentProperties { @@ -54,6 +56,13 @@ private OfferContentProperties(OfferAutoscaleProperties autoscaleProperties) [JsonProperty(PropertyName = Constants.Properties.OfferLastReplaceTimestamp, DefaultValueHandling = DefaultValueHandling.Ignore)] internal long? OfferLastReplaceTimestamp { get; private set; } + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + public static OfferContentProperties CreateManualOfferConent(int throughput) { return new OfferContentProperties(manualThroughput: throughput); diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/BoundingBoxProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/BoundingBoxProperties.cs index 003914e248..7348b4b710 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/BoundingBoxProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/BoundingBoxProperties.cs @@ -3,7 +3,9 @@ //------------------------------------------------------------ namespace Microsoft.Azure.Cosmos { + using System.Collections.Generic; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; /// /// Represents bounding box for geometry spatial path in the Azure Cosmos DB service @@ -70,5 +72,12 @@ public double Ymax { get; set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } } } \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/PermissionProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/PermissionProperties.cs index c4a15dc331..0cf9c8029a 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/PermissionProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/PermissionProperties.cs @@ -5,10 +5,12 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Collections.Generic; using System.Text; using Microsoft.Azure.Documents; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + using Newtonsoft.Json.Linq; /// /// Represents a permission in the Azure Cosmos DB service. @@ -203,5 +205,12 @@ public PartitionKey? ResourcePartitionKey [JsonProperty(PropertyName = Constants.Properties.ResourcePartitionKey, NullValueHandling = NullValueHandling.Ignore)] internal Documents.Routing.PartitionKeyInternal InternalResourcePartitionKey { get; private set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/ThroughputProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/ThroughputProperties.cs index e8bccead17..988cb1f3ce 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/ThroughputProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/ThroughputProperties.cs @@ -5,8 +5,10 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; /// /// Represents a throughput of the resources in the Azure Cosmos DB service. @@ -169,5 +171,12 @@ internal static ThroughputProperties CreateAutoscaleThroughput( /// [JsonProperty(PropertyName = Constants.Properties.OfferVersion, DefaultValueHandling = DefaultValueHandling.Ignore)] internal string OfferVersion { get; private set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/TriggerProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/TriggerProperties.cs index befdd74be3..9d4e044de3 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/TriggerProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/TriggerProperties.cs @@ -4,9 +4,11 @@ namespace Microsoft.Azure.Cosmos.Scripts { + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; using Newtonsoft.Json.Converters; + using Newtonsoft.Json.Linq; /// /// Represents a trigger in the Azure Cosmos DB service. @@ -88,5 +90,12 @@ public class TriggerProperties /// [JsonProperty(PropertyName = Constants.Properties.SelfLink, NullValueHandling = NullValueHandling.Ignore)] public string SelfLink { get; private set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/UserDefinedFunctionProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/UserDefinedFunctionProperties.cs index e34498dccc..170a8bc815 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/UserDefinedFunctionProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/UserDefinedFunctionProperties.cs @@ -4,8 +4,10 @@ namespace Microsoft.Azure.Cosmos.Scripts { + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; /// /// Represents a user defined function in the Azure Cosmos service. @@ -102,5 +104,12 @@ public class UserDefinedFunctionProperties /// [JsonProperty(PropertyName = Constants.Properties.SelfLink, NullValueHandling = NullValueHandling.Ignore)] public string SelfLink { get; private set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/UserProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/UserProperties.cs index 120ea09daf..7d5dab1df3 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/UserProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/UserProperties.cs @@ -5,8 +5,10 @@ namespace Microsoft.Azure.Cosmos { using System; + using System.Collections.Generic; using Microsoft.Azure.Documents; using Newtonsoft.Json; + using Newtonsoft.Json.Linq; /// /// Represents a user in the Azure Cosmos DB service. @@ -113,5 +115,12 @@ public string Id /// /// The self-link of the permissions associated with the user. internal string PermissionsLink => $"{this.SelfLink?.TrimEnd('/')}/{ this.Permissions}"; + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SettingsContractTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SettingsContractTests.cs index 5ae0f7bf69..9f131c3042 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SettingsContractTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/SettingsContractTests.cs @@ -242,9 +242,77 @@ public void ContainerSettingsSimpleTest() } [TestMethod] - public void ContainerSettingsDeserializeWithAdditionalDataTest() + public void SettingsDeserializeWithAdditionalDataTest() { - string cosmosSerialized = "{\"id\":\"2a9f501b-6948-4795-8fd1-797defb5c466\",\"partitionKey\":{\"paths\":[\"/partitionKey\"],\"kind\":\"Hash\"}}"; + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + this.DeserializeWithAdditionalDataTest(); + } + + [TestMethod] + public void ClientEncryptionKeyPropertiesDeserializeWithAdditionalDataTest() + { + byte[] bytes = new byte[1]; + ClientEncryptionKeyProperties clientEncryptionKeyProperties = new ClientEncryptionKeyProperties ( + id: "id", + encryptionAlgorithm: "encryptionAlgorithm", + wrappedDataEncryptionKey: bytes, + encryptionKeyWrapMetadata: new EncryptionKeyWrapMetadata("type", "name", "value") + ); + + string cosmosSerialized = SettingsContractTests.CosmosSerialize(clientEncryptionKeyProperties); + + JObject complexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname" } }); + + // Adding additional information + JObject jobject = JObject.Parse(cosmosSerialized); + jobject.Add(new JProperty("simple string", "policy value")); + jobject.Add(new JProperty("complex object", complexObject)); + + // Serialized string + string modifiedCosmosSerialized = SettingsContractTests.CosmosSerialize(jobject); + + ClientEncryptionKeyProperties deserSettings = SettingsContractTests.CosmosDeserialize(modifiedCosmosSerialized); + ClientEncryptionKeyProperties deserSettingsIntance2 = SettingsContractTests.CosmosDeserialize(modifiedCosmosSerialized); + + Assert.AreEqual("id", deserSettings.Id); + Assert.AreEqual("encryptionAlgorithm", deserSettings.EncryptionAlgorithm); + Assert.AreEqual(1, deserSettings.WrappedDataEncryptionKey.Length); + Assert.AreEqual(new EncryptionKeyWrapMetadata("type", "name", "value"), deserSettings.EncryptionKeyWrapMetadata); + + Assert.AreEqual(2, deserSettings.AdditionalProperties.Count); + Assert.AreEqual("policy value", (string)deserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual(complexObject.ToString(), JObject.FromObject(deserSettings.AdditionalProperties["complex object"]).ToString()); + + Assert.AreEqual(deserSettings, deserSettingsIntance2); // Testing equal function changes + + JObject newComplexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname1" } }); + // Adding additional information + JObject jobject_for_non_equality = JObject.Parse(cosmosSerialized); + jobject_for_non_equality.Add(new JProperty("simple string", "policy value")); + jobject_for_non_equality.Add(new JProperty("complex object", newComplexObject)); + + // Serialized string + string modifiedForNonEqualityCheckCosmosSerialized = SettingsContractTests.CosmosSerialize(jobject_for_non_equality); + ClientEncryptionKeyProperties deserSettingsIntance3 = SettingsContractTests.CosmosDeserialize(modifiedForNonEqualityCheckCosmosSerialized); + + Assert.AreNotEqual(deserSettingsIntance2, deserSettingsIntance3); // Testing equal function changes + } + + [TestMethod] + public void TriggerPropertiesDeserializeWithAdditionalDataTest() + { + TriggerProperties triggerProperties = new TriggerProperties + { + Body = "body" + }; + + string cosmosSerialized = SettingsContractTests.CosmosSerialize(triggerProperties); JObject complexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname" } }); @@ -256,19 +324,61 @@ public void ContainerSettingsDeserializeWithAdditionalDataTest() // Serialized string cosmosSerialized = SettingsContractTests.CosmosSerialize(jobject); - ContainerProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); + TriggerProperties deserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); - Assert.AreEqual("2a9f501b-6948-4795-8fd1-797defb5c466", containerDeserSettings.Id); - Assert.AreEqual("/partitionKey", containerDeserSettings.PartitionKeyPath); - Assert.AreEqual(2, containerDeserSettings.AdditionalProperties.Count); - Assert.AreEqual("policy value", containerDeserSettings.AdditionalProperties["simple string"]); - Assert.AreEqual(complexObject.ToString(), JObject.FromObject(containerDeserSettings.AdditionalProperties["complex object"]).ToString()); + Assert.AreEqual("body", deserSettings.Body); + Assert.AreEqual(2, deserSettings.AdditionalProperties.Count); + Assert.AreEqual("policy value", (string)deserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual(complexObject.ToString(), JObject.FromObject(deserSettings.AdditionalProperties["complex object"]).ToString()); } [TestMethod] - public void DatabaseSettingsDeserializeWithAdditionalDataTest() + public void ThroughputPropertiesDeserializeWithAdditionalDataTest() { - string cosmosSerialized = "{\"id\":\"2a9f501b-6948-4795-8fd1-797defb5c466\"}"; + ThroughputProperties manualThroughputProperties = ThroughputProperties.CreateManualThroughput(1); + ThroughputProperties autoscaleThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(2); + + string cosmosManualSerialized = SettingsContractTests.CosmosSerialize(manualThroughputProperties); + string cosmosAutoscaleSerialized = SettingsContractTests.CosmosSerialize(autoscaleThroughputProperties); + + JObject complexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname" } }); + + // Adding additional information + JObject manualJobject = JObject.Parse(cosmosManualSerialized); + manualJobject.Add(new JProperty("simple string", "policy value")); + manualJobject.Add(new JProperty("complex object", complexObject)); + + JObject autoscaleJobject = JObject.Parse(cosmosAutoscaleSerialized); + autoscaleJobject.Add(new JProperty("simple string", "policy value")); + autoscaleJobject.Add(new JProperty("complex object", complexObject)); + + // Serialized string + cosmosManualSerialized = SettingsContractTests.CosmosSerialize(manualJobject); + cosmosAutoscaleSerialized = SettingsContractTests.CosmosSerialize(autoscaleJobject); + + ThroughputProperties manualDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosManualSerialized); + ThroughputProperties autoscaleDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosAutoscaleSerialized); + + Assert.AreEqual(1, manualDeserSettings.Content.OfferThroughput); + Assert.AreEqual(2, manualDeserSettings.AdditionalProperties.Count); + Assert.AreEqual("policy value", (string)manualDeserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual(complexObject.ToString(), JObject.FromObject(manualDeserSettings.AdditionalProperties["complex object"]).ToString()); + + Assert.AreEqual(2, autoscaleDeserSettings.Content.OfferAutoscaleSettings.MaxThroughput); + Assert.AreEqual(2, autoscaleDeserSettings.AdditionalProperties.Count); + Assert.AreEqual("policy value", (string)autoscaleDeserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual(complexObject.ToString(), JObject.FromObject(autoscaleDeserSettings.AdditionalProperties["complex object"]).ToString()); + } + + [TestMethod] + public void BoundingBoxPropertiesDeserializeWithAdditionalDataTest() + { + BoundingBoxProperties boundingBoxProperties = new BoundingBoxProperties + { + Xmin = 10 + }; + + string cosmosSerialized = SettingsContractTests.CosmosSerialize(boundingBoxProperties); JObject complexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname" } }); @@ -280,18 +390,20 @@ public void DatabaseSettingsDeserializeWithAdditionalDataTest() // Serialized string cosmosSerialized = SettingsContractTests.CosmosSerialize(jobject); - DatabaseProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); + BoundingBoxProperties deserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); - Assert.AreEqual("2a9f501b-6948-4795-8fd1-797defb5c466", containerDeserSettings.Id); - Assert.AreEqual(2, containerDeserSettings.AdditionalProperties.Count); - Assert.AreEqual("policy value", containerDeserSettings.AdditionalProperties["simple string"]); - Assert.AreEqual(complexObject.ToString(), JObject.FromObject(containerDeserSettings.AdditionalProperties["complex object"]).ToString()); + Assert.AreEqual(10, deserSettings.Xmin); + Assert.AreEqual(2, deserSettings.AdditionalProperties.Count); + Assert.AreEqual("policy value", (string)deserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual(complexObject.ToString(), JObject.FromObject(deserSettings.AdditionalProperties["complex object"]).ToString()); } [TestMethod] - public void AccountPropertiesDeserializeWithAdditionalDataTest() + public void OfferContentPropertiesDeserializeWithAdditionalDataTest() { - string cosmosSerialized = "{\"id\":\"2a9f501b-6948-4795-8fd1-797defb5c466\"}"; + OfferContentProperties offerContentProperties = OfferContentProperties.CreateManualOfferConent(1); + + string cosmosSerialized = SettingsContractTests.CosmosSerialize(offerContentProperties); JObject complexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname" } }); @@ -303,18 +415,20 @@ public void AccountPropertiesDeserializeWithAdditionalDataTest() // Serialized string cosmosSerialized = SettingsContractTests.CosmosSerialize(jobject); - AccountProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); + OfferContentProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); - Assert.AreEqual("2a9f501b-6948-4795-8fd1-797defb5c466", containerDeserSettings.Id); + Assert.AreEqual(1, containerDeserSettings.OfferThroughput); Assert.AreEqual(2, containerDeserSettings.AdditionalProperties.Count); - Assert.AreEqual("policy value", containerDeserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual("policy value", (string)containerDeserSettings.AdditionalProperties["simple string"]); Assert.AreEqual(complexObject.ToString(), JObject.FromObject(containerDeserSettings.AdditionalProperties["complex object"]).ToString()); } [TestMethod] - public void ConflictSettingsDeserializeWithAdditionalDataTest() + public void OfferAutoscaleAutoUpgradePropertiesDeserializeWithAdditionalDataTest() { - string cosmosSerialized = "{\"id\":\"2a9f501b-6948-4795-8fd1-797defb5c466\"}"; + OfferAutoscaleAutoUpgradeProperties offerAutoscaleAutoUpgradeProperties = new OfferAutoscaleAutoUpgradeProperties(1); + + string cosmosSerialized = SettingsContractTests.CosmosSerialize(offerAutoscaleAutoUpgradeProperties); JObject complexObject = JObject.FromObject(new { id = 1, name = new { fname = "fname", lname = "lname" } }); @@ -326,16 +440,15 @@ public void ConflictSettingsDeserializeWithAdditionalDataTest() // Serialized string cosmosSerialized = SettingsContractTests.CosmosSerialize(jobject); - ConflictProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); + OfferAutoscaleAutoUpgradeProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); - Assert.AreEqual("2a9f501b-6948-4795-8fd1-797defb5c466", containerDeserSettings.Id); + Assert.AreEqual(1, containerDeserSettings.ThroughputProperties.IncrementPercent); Assert.AreEqual(2, containerDeserSettings.AdditionalProperties.Count); - Assert.AreEqual("policy value", containerDeserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual("policy value", (string)containerDeserSettings.AdditionalProperties["simple string"]); Assert.AreEqual(complexObject.ToString(), JObject.FromObject(containerDeserSettings.AdditionalProperties["complex object"]).ToString()); } - [TestMethod] - public void StoredProcedureSettingsDeserializeWithAdditionalDataTest() + private void DeserializeWithAdditionalDataTest() { string cosmosSerialized = "{\"id\":\"2a9f501b-6948-4795-8fd1-797defb5c466\"}"; @@ -349,11 +462,11 @@ public void StoredProcedureSettingsDeserializeWithAdditionalDataTest() // Serialized string cosmosSerialized = SettingsContractTests.CosmosSerialize(jobject); - StoredProcedureProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); + dynamic containerDeserSettings = SettingsContractTests.CosmosDeserialize(cosmosSerialized); Assert.AreEqual("2a9f501b-6948-4795-8fd1-797defb5c466", containerDeserSettings.Id); Assert.AreEqual(2, containerDeserSettings.AdditionalProperties.Count); - Assert.AreEqual("policy value", containerDeserSettings.AdditionalProperties["simple string"]); + Assert.AreEqual("policy value", (string)containerDeserSettings.AdditionalProperties["simple string"]); Assert.AreEqual(complexObject.ToString(), JObject.FromObject(containerDeserSettings.AdditionalProperties["complex object"]).ToString()); }