示例#1
0
        public void DefaultIncludesShouldNotBePopulated()
        {
            ContainerProperties containerSettings = new ContainerProperties("TestContainer", "/partitionKey");

            Assert.IsNotNull(containerSettings.IndexingPolicy);

            // Any exclude path should not auto-generate default indexing
            containerSettings.IndexingPolicy = new Cosmos.IndexingPolicy();
            containerSettings.IndexingPolicy.ExcludedPaths.Add(new Cosmos.ExcludedPath()
            {
                Path = "/some"
            });

            Assert.AreEqual(0, containerSettings.IndexingPolicy.IncludedPaths.Count);
            containerSettings.ValidateRequiredProperties();
            Assert.AreEqual(0, containerSettings.IndexingPolicy.IncludedPaths.Count);

            // None indexing mode should not auto-generate the default indexing
            containerSettings.IndexingPolicy = new Cosmos.IndexingPolicy
            {
                IndexingMode = Cosmos.IndexingMode.None
            };

            Assert.AreEqual(0, containerSettings.IndexingPolicy.IncludedPaths.Count);
            containerSettings.ValidateRequiredProperties();
            Assert.AreEqual(0, containerSettings.IndexingPolicy.IncludedPaths.Count);
        }
示例#2
0
        /// <summary>
        /// Applies the current Fluent definition and creates a container configuration.
        /// </summary>
        /// <returns>Builds the current Fluent configuration into an instance of <see cref="ContainerProperties"/>.</returns>
        public ContainerProperties Build()
        {
            ContainerProperties containerProperties = new ContainerProperties(id: this.containerName, partitionKeyPath: this.partitionKeyPath);

            if (this.indexingPolicy != null)
            {
                containerProperties.IndexingPolicy = this.indexingPolicy;
            }

            if (this.defaultTimeToLive.HasValue)
            {
                containerProperties.DefaultTimeToLive = this.defaultTimeToLive.Value;
            }

            if (this.timeToLivePropertyPath != null)
            {
#pragma warning disable 0612
                containerProperties.TimeToLivePropertyPath = this.timeToLivePropertyPath;
#pragma warning restore 0612
            }

            if (this.partitionKeyDefinitionVersion.HasValue)
            {
                containerProperties.PartitionKeyDefinitionVersion = this.partitionKeyDefinitionVersion.Value;
            }

            containerProperties.ValidateRequiredProperties();

            return(containerProperties);
        }
示例#3
0
        public void DefaultIncludesPopulated()
        {
            ContainerProperties containerSettings = new ContainerProperties("TestContainer", "/partitionKey");

            Assert.IsNotNull(containerSettings.IndexingPolicy);

            containerSettings.IndexingPolicy = new Cosmos.IndexingPolicy();
            Assert.AreEqual(0, containerSettings.IndexingPolicy.IncludedPaths.Count);

            // HAKC: Work-around till BE fixes defaults
            containerSettings.ValidateRequiredProperties();
            Assert.AreEqual(1, containerSettings.IndexingPolicy.IncludedPaths.Count);

            Cosmos.IncludedPath defaultEntry = containerSettings.IndexingPolicy.IncludedPaths[0];
            Assert.AreEqual(Cosmos.IndexingPolicy.DefaultPath, defaultEntry.Path);
            Assert.AreEqual(0, defaultEntry.Indexes.Count);
        }
示例#4
0
        private static void AssertSerializedPayloads(ContainerProperties settings, DocumentCollection documentCollection)
        {
            JsonSerializerSettings jsonSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            // HAKC: Work-around till BE fixes defaults
            settings.ValidateRequiredProperties();

            string containerSerialized  = JsonConvert.SerializeObject(settings, jsonSettings);
            string collectionSerialized = CosmosContainerSettingsTests.SerializeDocumentCollection(documentCollection);

            JObject containerJObject  = JObject.Parse(containerSerialized);
            JObject collectionJObject = JObject.Parse(collectionSerialized);

            Assert.AreEqual(JsonConvert.SerializeObject(OrderProeprties(collectionJObject)), JsonConvert.SerializeObject(OrderProeprties(containerJObject)));
        }
示例#5
0
        /// <summary>
        /// Applies the current Fluent definition and creates a container configuration.
        /// </summary>
        /// <returns>Builds the current Fluent configuration into an instance of <see cref="ContainerProperties"/>.</returns>
        public ContainerProperties Build()
        {
            ContainerProperties containerProperties = new ContainerProperties(id: this.containerName, partitionKeyPath: this.partitionKeyPath);

            if (this.indexingPolicy != null)
            {
                containerProperties.IndexingPolicy = this.indexingPolicy;
            }

            if (this.defaultTimeToLive.HasValue)
            {
                containerProperties.DefaultTimeToLive = this.defaultTimeToLive.Value;
            }

            if (this.timeToLivePropertyPath != null)
            {
                containerProperties.TimeToLivePropertyPath = timeToLivePropertyPath;
            }

            containerProperties.ValidateRequiredProperties();

            return(containerProperties);
        }