public void ContainerSettingsSimpleTest()
        {
            string id     = Guid.NewGuid().ToString();
            string pkPath = "/partitionKey";

            // Two equivalent definitions
            ContainerProperties cosmosContainerSettings = new ContainerProperties(id, pkPath);
            DocumentCollection  collection = new DocumentCollection()
            {
                Id           = id,
                PartitionKey = new PartitionKeyDefinition()
                {
                    Paths = new Collection <string>()
                    {
                        pkPath
                    },
                }
            };

            string cosmosSerialized = SettingsContractTests.CosmosSerialize(cosmosContainerSettings);
            string directSerialized = SettingsContractTests.DirectSerialize(collection);

            // Swap de-serialize and validate
            ContainerProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize <ContainerProperties>(directSerialized);
            DocumentCollection  collectionDeser        = SettingsContractTests.DirectDeSerialize <DocumentCollection>(cosmosSerialized);

            Assert.AreEqual(collection.Id, containerDeserSettings.Id);
            Assert.AreEqual(collection.PartitionKey.Paths[0], containerDeserSettings.PartitionKeyPath);

            Assert.AreEqual(cosmosContainerSettings.Id, collectionDeser.Id);
            Assert.AreEqual(cosmosContainerSettings.PartitionKeyPath, collectionDeser.PartitionKey.Paths[0]);
        }
        public void ConflictSettingsSerializeTest()
        {
            string id = Guid.NewGuid().ToString();

            ConflictProperties conflictSettings = new ConflictProperties()
            {
                Id            = id,
                OperationKind = Cosmos.OperationKind.Create,
                ResourceType  = typeof(StoredProcedureProperties)
            };

            Conflict conflict = new Conflict()
            {
                Id            = id,
                OperationKind = OperationKind.Create,
                ResourceType  = typeof(StoredProcedure)
            };

            string cosmosSerialized = SettingsContractTests.CosmosSerialize(conflictSettings);
            string directSerialized = SettingsContractTests.DirectSerialize(conflict);

            // Swap de-serialize and validate
            ConflictProperties conflictDeserSettings = SettingsContractTests.CosmosDeserialize <ConflictProperties>(directSerialized);
            Conflict           conflictDeser         = SettingsContractTests.DirectDeSerialize <Conflict>(cosmosSerialized);

            Assert.AreEqual(conflictDeserSettings.Id, conflictDeser.Id);
            Assert.AreEqual((int)conflictDeserSettings.OperationKind, (int)conflictDeser.OperationKind);
            Assert.AreEqual(typeof(StoredProcedure), conflictDeser.ResourceType);
            Assert.AreEqual(typeof(StoredProcedureProperties), conflictDeserSettings.ResourceType);
            Assert.AreEqual(conflictDeserSettings.Id, conflict.Id);
        }
예제 #3
0
        public void ContainerSettingsWithConflictResolution()
        {
            string id     = Guid.NewGuid().ToString();
            string pkPath = "/partitionKey";

            // Two equivalent definitions
            ContainerProperties cosmosContainerSettings = new ContainerProperties(id, pkPath)
            {
                ConflictResolutionPolicy = new Cosmos.ConflictResolutionPolicy()
                {
                    Mode                = Cosmos.ConflictResolutionMode.Custom,
                    ResolutionPath      = "/path",
                    ResolutionProcedure = "sp"
                }
            };

            DocumentCollection collection = new DocumentCollection()
            {
                Id = id,
                ConflictResolutionPolicy = new ConflictResolutionPolicy()
                {
                    Mode = ConflictResolutionMode.Custom,
                    ConflictResolutionPath      = "/path",
                    ConflictResolutionProcedure = "sp"
                }
            };

            string cosmosSerialized = SettingsContractTests.CosmosSerialize(cosmosContainerSettings);
            string directSerialized = SettingsContractTests.DirectSerialize(collection);

            // Swap de-serialize and validate
            ContainerProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize <ContainerProperties>(directSerialized);
            DocumentCollection  collectionDeser        = SettingsContractTests.DirectDeSerialize <DocumentCollection>(cosmosSerialized);

            Assert.AreEqual(cosmosContainerSettings.Id, collectionDeser.Id);
            Assert.AreEqual((int)cosmosContainerSettings.ConflictResolutionPolicy.Mode, (int)collectionDeser.ConflictResolutionPolicy.Mode);
            Assert.AreEqual(cosmosContainerSettings.ConflictResolutionPolicy.ResolutionPath, collectionDeser.ConflictResolutionPolicy.ConflictResolutionPath);
            Assert.AreEqual(cosmosContainerSettings.ConflictResolutionPolicy.ResolutionProcedure, collectionDeser.ConflictResolutionPolicy.ConflictResolutionProcedure);
        }
예제 #4
0
        public void DatabaseSettingsSerializeTest()
        {
            string id = Guid.NewGuid().ToString();

            DatabaseProperties databaseSettings = new DatabaseProperties()
            {
                Id = id
            };

            Database db = new Database()
            {
                Id = id
            };

            string cosmosSerialized = SettingsContractTests.CosmosSerialize(databaseSettings);
            string directSerialized = SettingsContractTests.DirectSerialize(db);

            // Swap de-serialize and validate
            DatabaseProperties dbDeserSettings = SettingsContractTests.CosmosDeserialize <DatabaseProperties>(directSerialized);
            Database           dbDeser         = SettingsContractTests.DirectDeSerialize <Database>(cosmosSerialized);

            Assert.AreEqual(dbDeserSettings.Id, dbDeser.Id);
            Assert.AreEqual(dbDeserSettings.Id, db.Id);
        }
예제 #5
0
        public void ContainerSettingsWithIndexingPolicyTest()
        {
            string id     = Guid.NewGuid().ToString();
            string pkPath = "/partitionKey";

            // Two equivalent definitions
            ContainerProperties cosmosContainerSettings = new ContainerProperties(id, pkPath);

            cosmosContainerSettings.IndexingPolicy.Automatic = true;
            cosmosContainerSettings.IndexingPolicy.IncludedPaths.Add(new Cosmos.IncludedPath()
            {
                Path = "/id1/*"
            });

            Cosmos.UniqueKey cuk1 = new Cosmos.UniqueKey();
            cuk1.Paths.Add("/u1");
            cosmosContainerSettings.UniqueKeyPolicy.UniqueKeys.Add(cuk1);

            DocumentCollection collection = new DocumentCollection()
            {
                Id           = id,
                PartitionKey = new PartitionKeyDefinition()
                {
                    Paths = new Collection <string>()
                    {
                        pkPath
                    },
                }
            };

            collection.IndexingPolicy.Automatic = true;
            collection.IndexingPolicy.IncludedPaths.Add(new Documents.IncludedPath()
            {
                Path = "/id1/*"
            });

            Documents.UniqueKey duk1 = new Documents.UniqueKey();
            duk1.Paths.Add("/u1");
            collection.UniqueKeyPolicy.UniqueKeys.Add(duk1);

            string cosmosSerialized = SettingsContractTests.CosmosSerialize(cosmosContainerSettings);
            string directSerialized = SettingsContractTests.DirectSerialize(collection);

            // Swap de-serialize and validate
            ContainerProperties containerDeserSettings = SettingsContractTests.CosmosDeserialize <ContainerProperties>(directSerialized);
            DocumentCollection  collectionDeser        = SettingsContractTests.DirectDeSerialize <DocumentCollection>(cosmosSerialized);

            Assert.AreEqual(collection.Id, containerDeserSettings.Id);
            Assert.AreEqual(collection.PartitionKey.Paths[0], containerDeserSettings.PartitionKeyPath);
            Assert.AreEqual(collection.IndexingPolicy.Automatic, containerDeserSettings.IndexingPolicy.Automatic);
            Assert.AreEqual(collection.IndexingPolicy.IncludedPaths.Count, containerDeserSettings.IndexingPolicy.IncludedPaths.Count);
            Assert.AreEqual(collection.IndexingPolicy.IncludedPaths[0].Path, containerDeserSettings.IndexingPolicy.IncludedPaths[0].Path);
            Assert.AreEqual(collection.IndexingPolicy.IncludedPaths[0].Indexes.Count, containerDeserSettings.IndexingPolicy.IncludedPaths[0].Indexes.Count);
            Assert.AreEqual(collection.UniqueKeyPolicy.UniqueKeys.Count, containerDeserSettings.UniqueKeyPolicy.UniqueKeys.Count);
            Assert.AreEqual(collection.UniqueKeyPolicy.UniqueKeys[0].Paths.Count, containerDeserSettings.UniqueKeyPolicy.UniqueKeys[0].Paths.Count);
            Assert.AreEqual(collection.UniqueKeyPolicy.UniqueKeys[0].Paths[0], containerDeserSettings.UniqueKeyPolicy.UniqueKeys[0].Paths[0]);

            Assert.AreEqual(cosmosContainerSettings.Id, collectionDeser.Id);
            Assert.AreEqual(cosmosContainerSettings.PartitionKeyPath, collectionDeser.PartitionKey.Paths[0]);
            Assert.AreEqual(cosmosContainerSettings.IndexingPolicy.Automatic, collectionDeser.IndexingPolicy.Automatic);
            Assert.AreEqual(cosmosContainerSettings.IndexingPolicy.IncludedPaths.Count, collectionDeser.IndexingPolicy.IncludedPaths.Count);
            Assert.AreEqual(cosmosContainerSettings.IndexingPolicy.IncludedPaths[0].Path, collectionDeser.IndexingPolicy.IncludedPaths[0].Path);
            Assert.AreEqual(cosmosContainerSettings.IndexingPolicy.IncludedPaths[0].Indexes.Count, collectionDeser.IndexingPolicy.IncludedPaths[0].Indexes.Count);
            Assert.AreEqual(cosmosContainerSettings.UniqueKeyPolicy.UniqueKeys.Count, collectionDeser.UniqueKeyPolicy.UniqueKeys.Count);
            Assert.AreEqual(cosmosContainerSettings.UniqueKeyPolicy.UniqueKeys[0].Paths.Count, collectionDeser.UniqueKeyPolicy.UniqueKeys[0].Paths.Count);
            Assert.AreEqual(cosmosContainerSettings.UniqueKeyPolicy.UniqueKeys[0].Paths[0], collectionDeser.UniqueKeyPolicy.UniqueKeys[0].Paths[0]);
        }